Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions core/account/native/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Account, type Asset, Keypair, MuxedAccount, xdr } from "stellar-sdk";
import { assert } from "@/common/assert/assert.ts";
import { StrKey } from "@/strkeys/index.ts";
import { isMuxedId } from "@/common/verifiers/is-muxed-id.ts";
import { isMuxedId } from "@/common/type-guards/is-muxed-id.ts";
import type { Ed25519PublicKey, MuxedAddress } from "@/strkeys/types.ts";
import type { TransactionSigner } from "@/signer/types.ts";
import type { Signer } from "@/signer/types.ts";
import * as E from "@/account/native/error.ts";
import type {
WithSigner,
Expand All @@ -14,7 +14,7 @@ import type {

export class NativeAccount implements NativeAccountType {
protected _address: Ed25519PublicKey;
protected _masterSigner?: TransactionSigner;
protected _masterSigner?: Signer;

private constructor(address: Ed25519PublicKey) {
assert(
Expand Down Expand Up @@ -77,18 +77,18 @@ export class NativeAccount implements NativeAccountType {
// WithSigner methods
// ----------------

static fromMasterSigner(signer: TransactionSigner) {
static fromMasterSigner(signer: Signer) {
return NativeAccount.fromAddress(signer.publicKey()).withMasterSigner(
signer
);
}

withMasterSigner(signer: TransactionSigner): WithSigner<this> {
withMasterSigner(signer: Signer): WithSigner<this> {
this._masterSigner = signer;
return this as WithSigner<this>;
}

signer(): TransactionSigner {
signer(): Signer {
assert(this._masterSigner, new E.MISSING_MASTER_SIGNER(this._address));
return this._masterSigner;
}
Expand Down
6 changes: 3 additions & 3 deletions core/account/native/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Asset, xdr } from "stellar-sdk";
import type { Ed25519PublicKey, MuxedAddress } from "@/strkeys/types.ts";
import type { MultiSigSchema, TransactionSigner } from "@/signer/types.ts";
import type { MultiSigSchema, Signer } from "@/signer/types.ts";

export type MuxedId = `${number}`;

Expand All @@ -12,11 +12,11 @@ export type NativeAccountType = {
};

export type WithoutSigner<AccountType> = AccountType & {
withMasterSigner(signer: TransactionSigner): WithSigner<NativeAccountType>;
withMasterSigner(signer: Signer): WithSigner<NativeAccountType>;
};

export type WithSigner<AccountType> = AccountType & {
signer(): TransactionSigner;
signer(): Signer;
};

export type WithMultiSig<AccountType> = AccountType & {
Expand Down
4 changes: 2 additions & 2 deletions core/asset/sac/index.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
import { Server } from "stellar-sdk/rpc";
import { toStellarAssetCanonicalString } from "@/asset/sep11/index.ts";
import { PIPE_ClassicTransaction } from "@/pipelines/classic-transaction/index.ts";
import type { TransactionSigner } from "@/signer/types.ts";
import type { Signer } from "@/signer/types.ts";
import type { Ed25519PublicKey } from "@/strkeys/types.ts";
import * as SACError from "@/asset/sac/error.ts";

Expand All @@ -40,7 +40,7 @@ describe("[Testnet] Stellar Asset Contract", disableSanitizeConfig, () => {
};

const addTrustline = async (
users: TransactionSigner[],
users: Signer[],
asset: Asset,
networkConfig: NetworkConfig,
config: TransactionConfig
Expand Down
2 changes: 1 addition & 1 deletion core/asset/sac/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
type BaseInvocation,
type ContractInput,
} from "@/asset/sac/types.ts";
import { isDefined } from "@/common/verifiers/is-defined.ts";
import { isDefined } from "@/common/type-guards/is-defined.ts";

/**
* Client class for interacting with Stellar Asset Contracts (SAC).
Expand Down
2 changes: 1 addition & 1 deletion core/common/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export { regex } from "@/common/regex/index.ts";
export * from "@/common/assert/index.ts";
export * from "@/common/verifiers/index.ts";
export * from "@/common/type-guards/index.ts";
export * from "@/common/helpers/index.ts";
export * from "@/common/scval/index.ts";
export type * from "@/common/types/index.ts";
10 changes: 10 additions & 0 deletions core/common/type-guards/has-function.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const hasFunction = <T>(
obj: NonNullable<T>,
key: PropertyKey
): key is keyof T & string => {
return (
typeof obj === "object" &&
key in obj &&
typeof (obj as Record<PropertyKey, unknown>)[key] === "function"
);
};
7 changes: 7 additions & 0 deletions core/common/type-guards/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export * from "@/common/type-guards/is-defined.ts";
export * from "@/common/type-guards/is-fee-bump-transaction.ts";
export * from "@/common/type-guards/is-muxed-id.ts";
export * from "@/common/type-guards/is-signing-threshold.ts";
export * from "@/common/type-guards/is-smart-contract-transaction.ts";
export * from "@/common/type-guards/is-transaction.ts";
export * from "./is-signer.ts";
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {
} from "stellar-sdk";
import { NetworkConfig } from "@/network/index.ts";
import { StrKey } from "@/strkeys/index.ts";
import { isTransaction } from "@/common/verifiers/is-transaction.ts";
import { isFeeBumpTransaction } from "@/common/verifiers/is-fee-bump-transaction.ts";
import { isSigningThreshold } from "@/common/verifiers/is-signing-threshold.ts";
import { isSmartContractTransaction } from "@/common/verifiers/is-smart-contract-transaction.ts";
import { isTransaction } from "@/common/type-guards/is-transaction.ts";
import { isFeeBumpTransaction } from "@/common/type-guards/is-fee-bump-transaction.ts";
import { isSigningThreshold } from "@/common/type-guards/is-signing-threshold.ts";
import { isSmartContractTransaction } from "@/common/type-guards/is-smart-contract-transaction.ts";

describe("Verifiers", () => {
describe("isEd25519PublicKey", () => {
Expand Down
3 changes: 3 additions & 0 deletions core/common/type-guards/is-defined.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const isDefined = <T>(value: T): value is NonNullable<T> => {
return value !== undefined && value !== null;
};
14 changes: 14 additions & 0 deletions core/common/type-guards/is-signer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { Signer } from "@/signer/types.ts";
import { isDefined } from "@/common/index.ts";
import { hasFunction } from "@/common/type-guards/has-function.ts";

export const isSigner = (signer: unknown): signer is Signer => {
return (
isDefined(signer) &&
hasFunction(signer, "publicKey") &&
hasFunction(signer, "sign") &&
hasFunction(signer, "signTransaction") &&
hasFunction(signer, "signSorobanAuthEntry") &&
hasFunction(signer, "signsFor")
);
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { FeeBumpTransaction, Transaction } from "stellar-sdk";
import { getOperationsFromTransaction } from "@/common/helpers/transaction.ts";
import { isTransaction } from "@/common/verifiers/is-transaction.ts";
import { isFeeBumpTransaction } from "@/common/verifiers/is-fee-bump-transaction.ts";
import { isTransaction } from "@/common/type-guards/is-transaction.ts";
import { isFeeBumpTransaction } from "@/common/type-guards/is-fee-bump-transaction.ts";

export const SMART_CONTRACT_OPERATIONS = [
"invokeHostFunction",
Expand Down
4 changes: 2 additions & 2 deletions core/common/types/transaction-config/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { TransactionSigner } from "@/signer/types.ts";
import type { Signer } from "@/signer/types.ts";
import type {
ContractId,
Ed25519PublicKey,
Expand All @@ -9,7 +9,7 @@ export type TransactionConfig = {
fee: BaseFee;
source: Ed25519PublicKey;
timeout: number;
signers: TransactionSigner[];
signers: Signer[];
};

export type BaseFee = `${number}`;
Expand Down
7 changes: 0 additions & 7 deletions core/common/verifiers/index.ts

This file was deleted.

3 changes: 0 additions & 3 deletions core/common/verifiers/is-defined.ts

This file was deleted.

20 changes: 0 additions & 20 deletions core/common/verifiers/is-transaction-signer.ts

This file was deleted.

2 changes: 1 addition & 1 deletion core/deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@colibri/core",
"version": "0.12.0",
"version": "0.13.0",
"license": "MIT",
"exports": {
".": "./mod.ts"
Expand Down
16 changes: 8 additions & 8 deletions core/error/index.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ describe("ColibriError", () => {
};
const meta: BaseMeta = { data: { accountId: "GABC" } };
const shape: ColibriErrorShape<"ACC_001", BaseMeta> = {
domain: "accounts",
source: "@colibri/accounts",
domain: "account",
source: "@colibri/account",
code: "ACC_001",
message: "Invalid account key",
details: "malformed key",
Expand All @@ -31,8 +31,8 @@ describe("ColibriError", () => {
assert(e instanceof Error);
assert(e instanceof ColibriError);
assertStrictEquals(e.name, "ColibriError ACC_001");
assertStrictEquals(e.domain, "accounts");
assertStrictEquals(e.source, "@colibri/accounts");
assertStrictEquals(e.domain, "account");
assertStrictEquals(e.source, "@colibri/account");
assertStrictEquals(e.code, "ACC_001");
assertStrictEquals(e.message, "Invalid account key");
assertStrictEquals(e.details, "malformed key");
Expand Down Expand Up @@ -145,14 +145,14 @@ describe("ColibriError", () => {
it("wraps native Error and keeps stack in details and cause in meta", () => {
const native = new Error("boom");
const wrapped = ColibriError.fromUnknown(native, {
domain: "accounts",
source: "@colibri/accounts",
domain: "account",
source: "@colibri/account",
code: "ACC_999",
});

assert(wrapped instanceof ColibriError);
assertEquals(wrapped.domain, "accounts");
assertEquals(wrapped.source, "@colibri/accounts");
assertEquals(wrapped.domain, "account");
assertEquals(wrapped.source, "@colibri/account");
assertEquals(wrapped.code, "ACC_999");
assertEquals(wrapped.message, "boom");
assert(typeof wrapped.details === "string"); // stack string
Expand Down
2 changes: 1 addition & 1 deletion core/error/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export type ErrorDomain =
| "verifiers"
| "helpers"
| "core"
| "accounts"
| "signer"
| "pipelines"
| "plugins"
| "rpc"
Expand Down
2 changes: 1 addition & 1 deletion core/event/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { ScValParsed } from "@/common/scval/types.ts";
import { isEventId, type EventId } from "@/event/event-id/index.ts";
import { EventType, type IEvent } from "@/event/types.ts";
import type { ContractId } from "@/strkeys/types.ts";
import { isDefined } from "@/common/verifiers/is-defined.ts";
import { isDefined } from "@/common/type-guards/is-defined.ts";
import { StrKey } from "@/strkeys/index.ts";

export class Event implements IEvent {
Expand Down
2 changes: 1 addition & 1 deletion core/event/parsing/ledger-close-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { EventFilter } from "@/event/event-filter/index.ts";
import type { EventHandler } from "@/event/types.ts";
import * as E from "@/event/parsing/error.ts";
import { assert } from "@/common/assert/assert.ts";
import { isDefined } from "@/common/verifiers/is-defined.ts";
import { isDefined } from "@/common/type-guards/is-defined.ts";

export const isLedgerCloseMetaV1 = (
metadataXdr: xdr.LedgerCloseMeta
Expand Down
2 changes: 1 addition & 1 deletion core/network/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {
FutureNetCustomConfig,
TestNetNetCustomConfig,
} from "@/network/types.ts";
import { isDefined } from "@/common/verifiers/is-defined.ts";
import { isDefined } from "@/common/type-guards/is-defined.ts";

export * as NetworkProviders from "@/network/providers/index.ts";

Expand Down
2 changes: 1 addition & 1 deletion core/processes/assemble-transaction/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
import * as E from "@/processes/assemble-transaction/error.ts";

import { assert } from "@/common/assert/assert.ts";
import { isSmartContractTransaction } from "@/common/verifiers/is-smart-contract-transaction.ts";
import { isSmartContractTransaction } from "@/common/type-guards/is-smart-contract-transaction.ts";
import {
getOperationsFromTransaction,
getOperationType,
Expand Down
4 changes: 2 additions & 2 deletions core/processes/envelope-signing-requirements/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import type {
EnvelopeSigningRequirementsOutput,
} from "@/processes/envelope-signing-requirements/types.ts";
import * as E from "@/processes/envelope-signing-requirements/error.ts";
import { isFeeBumpTransaction } from "@/common/verifiers/is-fee-bump-transaction.ts";
import { isTransaction } from "@/common/verifiers/is-transaction.ts";
import { isFeeBumpTransaction } from "@/common/type-guards/is-fee-bump-transaction.ts";
import { isTransaction } from "@/common/type-guards/is-transaction.ts";
import { muxedAddressToBaseAccount } from "@/transformers/address/index.ts";
import { ColibriError } from "@/error/index.ts";
import { getRequiredOperationThresholdForClassicOperation } from "@/transformers/auth/index.ts";
Expand Down
17 changes: 8 additions & 9 deletions core/processes/sign-auth-entries/error.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { P_SignAuthEntries } from "@/processes/sign-auth-entries/index.ts";
import * as E from "@/processes/sign-auth-entries/error.ts";
import type { SignAuthEntriesInput } from "@/processes/sign-auth-entries/types.ts";
import { NetworkConfig } from "@/network/index.ts";
import type { TransactionSigner } from "@/signer/types.ts";
import type { Signer } from "@/signer/types.ts";
import type { Ed25519PublicKey } from "@/strkeys/types.ts";

describe("SignAuthEntries", () => {
const { networkPassphrase } = NetworkConfig.TestNet();

type MockSigner = TransactionSigner & {
type MockSigner = Signer & {
calls: number;
lastEntry?: xdr.SorobanAuthorizationEntry;
lastValidUntil?: number;
Expand Down Expand Up @@ -53,16 +53,14 @@ describe("SignAuthEntries", () => {
passphrase: string
) => Promise<xdr.SorobanAuthorizationEntry>
): MockSigner => {
const signTransaction: TransactionSigner["signTransaction"] = async (
..._args: Parameters<TransactionSigner["signTransaction"]>
const signTransaction: Signer["signTransaction"] = async (
..._args: Parameters<Signer["signTransaction"]>
) => {
return await Promise.resolve(
undefined as unknown as Awaited<
ReturnType<TransactionSigner["signTransaction"]>
>
undefined as unknown as Awaited<ReturnType<Signer["signTransaction"]>>
);
};
const sign: TransactionSigner["sign"] = (b: Buffer): Buffer => {
const sign: Signer["sign"] = (b: Buffer): Buffer => {
return b;
};

Expand All @@ -71,6 +69,7 @@ describe("SignAuthEntries", () => {
publicKey: () => publicKey as Ed25519PublicKey,
sign,
signTransaction,
signsFor: (target: Ed25519PublicKey | string) => target === publicKey,
async signSorobanAuthEntry(entry, validUntil, passphrase) {
signer.calls++;
signer.lastEntry = entry;
Expand Down Expand Up @@ -138,7 +137,7 @@ describe("SignAuthEntries", () => {
() =>
P_SignAuthEntries().run({
auth: [entry],
signers: undefined as unknown as TransactionSigner[],
signers: undefined as unknown as Signer[],
rpc: makeRpc(),
networkPassphrase,
}),
Expand Down
5 changes: 1 addition & 4 deletions core/processes/sign-auth-entries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
getAddressTypeFromAuthEntry,
} from "@/common/helpers/xdr/general.ts";
import { ResultOrError } from "@/common/deferred/result-or-error.ts";
import type { TransactionSigner } from "@/signer/types.ts";

const signAuthEntriesProcess = async (
input: SignAuthEntriesInput
Expand Down Expand Up @@ -70,9 +69,7 @@ const signAuthEntriesProcess = async (
if (addressType === "scAddressTypeAccount") {
const requiredSigner = getAddressSignerFromAuthEntry(authEntry);

const signer = signers.find(
(s) => s.publicKey() === requiredSigner
) as TransactionSigner;
const signer = signers.find((s) => s.signsFor(requiredSigner));

assert(signer, new E.MISSING_SIGNER(input, requiredSigner, authEntry));

Expand Down
Loading