passkey-kit 0.12.1 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +408 -227
- package/{types → dist}/base.d.ts +1 -0
- package/dist/base.d.ts.map +1 -0
- package/{src/base.ts → dist/base.js} +8 -10
- package/dist/base.js.map +1 -0
- package/dist/base64url.d.ts +18 -0
- package/dist/base64url.d.ts.map +1 -0
- package/dist/base64url.js +18 -0
- package/dist/base64url.js.map +1 -0
- package/dist/constants.d.ts +91 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +115 -0
- package/dist/constants.js.map +1 -0
- package/dist/contract-errors.d.ts +69 -0
- package/dist/contract-errors.d.ts.map +1 -0
- package/dist/contract-errors.js +132 -0
- package/dist/contract-errors.js.map +1 -0
- package/dist/errors.d.ts +163 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +244 -0
- package/dist/errors.js.map +1 -0
- package/dist/events.d.ts +94 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +92 -0
- package/dist/events.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/indexer/codec.d.ts +18 -0
- package/dist/indexer/codec.d.ts.map +1 -0
- package/dist/indexer/codec.js +32 -0
- package/dist/indexer/codec.js.map +1 -0
- package/dist/indexer/index.d.ts +25 -0
- package/dist/indexer/index.d.ts.map +1 -0
- package/dist/indexer/index.js +34 -0
- package/dist/indexer/index.js.map +1 -0
- package/dist/indexer/mercury.d.ts +94 -0
- package/dist/indexer/mercury.d.ts.map +1 -0
- package/dist/indexer/mercury.js +245 -0
- package/dist/indexer/mercury.js.map +1 -0
- package/dist/indexer/stellar-indexer.d.ts +115 -0
- package/dist/indexer/stellar-indexer.d.ts.map +1 -0
- package/dist/indexer/stellar-indexer.js +279 -0
- package/dist/indexer/stellar-indexer.js.map +1 -0
- package/dist/indexer/types.d.ts +73 -0
- package/dist/indexer/types.d.ts.map +1 -0
- package/dist/indexer/types.js +9 -0
- package/dist/indexer/types.js.map +1 -0
- package/dist/kit/auth-payload.d.ts +106 -0
- package/dist/kit/auth-payload.d.ts.map +1 -0
- package/dist/kit/auth-payload.js +227 -0
- package/dist/kit/auth-payload.js.map +1 -0
- package/dist/kit/deploy-ops.d.ts +45 -0
- package/dist/kit/deploy-ops.d.ts.map +1 -0
- package/dist/kit/deploy-ops.js +69 -0
- package/dist/kit/deploy-ops.js.map +1 -0
- package/dist/kit/tx-ops.d.ts +95 -0
- package/dist/kit/tx-ops.d.ts.map +1 -0
- package/dist/kit/tx-ops.js +125 -0
- package/dist/kit/tx-ops.js.map +1 -0
- package/dist/kit/wallet-ops.d.ts +59 -0
- package/dist/kit/wallet-ops.d.ts.map +1 -0
- package/dist/kit/wallet-ops.js +122 -0
- package/dist/kit/wallet-ops.js.map +1 -0
- package/dist/kit/webauthn-ops.d.ts +55 -0
- package/dist/kit/webauthn-ops.d.ts.map +1 -0
- package/dist/kit/webauthn-ops.js +79 -0
- package/dist/kit/webauthn-ops.js.map +1 -0
- package/dist/kit.d.ts +132 -0
- package/dist/kit.d.ts.map +1 -0
- package/dist/kit.js +290 -0
- package/dist/kit.js.map +1 -0
- package/dist/managers/credential-manager.d.ts +39 -0
- package/dist/managers/credential-manager.d.ts.map +1 -0
- package/dist/managers/credential-manager.js +47 -0
- package/dist/managers/credential-manager.js.map +1 -0
- package/dist/managers/index.d.ts +7 -0
- package/dist/managers/index.d.ts.map +1 -0
- package/dist/managers/index.js +7 -0
- package/dist/managers/index.js.map +1 -0
- package/dist/managers/signer-manager.d.ts +62 -0
- package/dist/managers/signer-manager.d.ts.map +1 -0
- package/dist/managers/signer-manager.js +111 -0
- package/dist/managers/signer-manager.js.map +1 -0
- package/dist/managers/submission-manager.d.ts +52 -0
- package/dist/managers/submission-manager.d.ts.map +1 -0
- package/dist/managers/submission-manager.js +77 -0
- package/dist/managers/submission-manager.js.map +1 -0
- package/dist/relayer.d.ts +61 -0
- package/dist/relayer.d.ts.map +1 -0
- package/dist/relayer.js +122 -0
- package/dist/relayer.js.map +1 -0
- package/dist/rpc-data.d.ts +45 -0
- package/dist/rpc-data.d.ts.map +1 -0
- package/dist/rpc-data.js +61 -0
- package/dist/rpc-data.js.map +1 -0
- package/dist/sac.d.ts +31 -0
- package/dist/sac.d.ts.map +1 -0
- package/dist/sac.js +47 -0
- package/dist/sac.js.map +1 -0
- package/dist/server.d.ts +79 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +152 -0
- package/dist/server.js.map +1 -0
- package/dist/signers.d.ts +83 -0
- package/dist/signers.d.ts.map +1 -0
- package/dist/signers.js +124 -0
- package/dist/signers.js.map +1 -0
- package/dist/storage/index.d.ts +13 -0
- package/dist/storage/index.d.ts.map +1 -0
- package/dist/storage/index.js +12 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/indexeddb.d.ts +26 -0
- package/dist/storage/indexeddb.d.ts.map +1 -0
- package/dist/storage/indexeddb.js +100 -0
- package/dist/storage/indexeddb.js.map +1 -0
- package/dist/storage/localStorage.d.ts +22 -0
- package/dist/storage/localStorage.d.ts.map +1 -0
- package/dist/storage/localStorage.js +86 -0
- package/dist/storage/localStorage.js.map +1 -0
- package/dist/storage/memory.d.ts +18 -0
- package/dist/storage/memory.d.ts.map +1 -0
- package/dist/storage/memory.js +41 -0
- package/dist/storage/memory.js.map +1 -0
- package/dist/types.d.ts +136 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +39 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +72 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +253 -0
- package/dist/utils.js.map +1 -0
- package/dist/validation.d.ts +42 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +75 -0
- package/dist/validation.js.map +1 -0
- package/dist/version.d.ts +7 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +9 -0
- package/dist/version.js.map +1 -0
- package/package.json +47 -20
- package/.claude/settings.local.json +0 -20
- package/.cursorrules +0 -170
- package/.gitattributes +0 -2
- package/.github/workflows/release.yml +0 -21
- package/.vscode/settings.json +0 -6
- package/PROPOSAL.md +0 -397
- package/cheatsheet.txt +0 -18
- package/clone-js-sdk.sh +0 -21
- package/packages/passkey-kit-sdk/README.md +0 -54
- package/packages/passkey-kit-sdk/package.json +0 -21
- package/packages/passkey-kit-sdk/src/index.ts +0 -171
- package/packages/passkey-kit-sdk/tsconfig.json +0 -98
- package/packages/passkey-kit-sdk/types/index.d.ts +0 -190
- package/packages/sac-sdk/README.md +0 -54
- package/packages/sac-sdk/package.json +0 -21
- package/packages/sac-sdk/src/index.ts +0 -586
- package/packages/sac-sdk/tsconfig.json +0 -98
- package/packages/sac-sdk/types/index.d.ts +0 -532
- package/pnpm-workspace.yaml +0 -2
- package/src/index.ts +0 -5
- package/src/kit.ts +0 -823
- package/src/sac.ts +0 -29
- package/src/server.ts +0 -179
- package/src/types.ts +0 -32
- package/tsconfig.json +0 -28
- package/types/index.d.ts +0 -5
- package/types/kit.d.ts +0 -95
- package/types/sac.d.ts +0 -13
- package/types/server.d.ts +0 -29
- package/types/types.d.ts +0 -22
package/{types → dist}/base.d.ts
RENAMED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../src/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;AAOjD,qBAAa,WAAW;IACb,MAAM,EAAE,MAAM,GAAG,SAAS,CAAA;IAC1B,GAAG,EAAE,MAAM,GAAG,SAAS,CAAA;gBAElB,MAAM,CAAC,EAAE,MAAM;CAM9B"}
|
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
import { Server } from "@stellar/stellar-sdk/rpc"
|
|
2
|
-
|
|
1
|
+
import { Server } from "@stellar/stellar-sdk/rpc";
|
|
3
2
|
// TODO consider adding support for a signAuthEntry method that conforms to the ed25519 signature scheme of this passkey interface
|
|
4
3
|
// once we do that we can clean the code a little with the `xdr.HashIdPreimage.envelopeTypeSorobanAuthorization` stuff
|
|
5
4
|
// ... note I've re-read the above and I've currently got no clue what this is asking for. Maybe check git-blame for when it was added to try and find some context
|
|
6
5
|
// actually this is just talking about adding support for signing transactions with an ed25519 key as well as a passkey. Simple enough
|
|
7
|
-
|
|
8
6
|
export class PasskeyBase {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
constructor(rpcUrl?: string) {
|
|
7
|
+
rpcUrl;
|
|
8
|
+
rpc;
|
|
9
|
+
constructor(rpcUrl) {
|
|
13
10
|
if (rpcUrl) {
|
|
14
|
-
this.rpcUrl = rpcUrl
|
|
15
|
-
this.rpc = new Server(rpcUrl)
|
|
11
|
+
this.rpcUrl = rpcUrl;
|
|
12
|
+
this.rpc = new Server(rpcUrl);
|
|
16
13
|
}
|
|
17
14
|
}
|
|
18
|
-
}
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=base.js.map
|
package/dist/base.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../src/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;AAEjD,kIAAkI;AAClI,sHAAsH;AACtH,mKAAmK;AACnK,sIAAsI;AAEtI,MAAM,OAAO,WAAW;IACb,MAAM,CAAoB;IAC1B,GAAG,CAAoB;IAE9B,YAAY,MAAe;QACvB,IAAI,MAAM,EAAE,CAAC;YACT,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;YACpB,IAAI,CAAC,GAAG,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC,CAAA;QACjC,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `base64url` interop shim.
|
|
3
|
+
*
|
|
4
|
+
* The `base64url` package ships ESM-style type declarations
|
|
5
|
+
* (`export default base64url`) over a CommonJS runtime. Under NodeNext module
|
|
6
|
+
* resolution the default import is typed as the module namespace object rather
|
|
7
|
+
* than the callable `Base64Url`, so both calling it (`base64url(...)`) and
|
|
8
|
+
* member access (`base64url.toBuffer(...)`) fail to type-check. At runtime
|
|
9
|
+
* `esModuleInterop` already yields the callable, so this is a type-only
|
|
10
|
+
* correction, centralized here rather than repeated at every call site.
|
|
11
|
+
*
|
|
12
|
+
* Every module in the kit imports base64url from here, never directly from the
|
|
13
|
+
* package, so the interop fix lives in exactly one place.
|
|
14
|
+
*/
|
|
15
|
+
import { type Base64Url } from "base64url";
|
|
16
|
+
declare const base64url: Base64Url;
|
|
17
|
+
export default base64url;
|
|
18
|
+
//# sourceMappingURL=base64url.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64url.d.ts","sourceRoot":"","sources":["../src/base64url.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAyB,EAAE,KAAK,SAAS,EAAE,MAAM,WAAW,CAAC;AAE7D,QAAA,MAAM,SAAS,EAAkC,SAAS,CAAC;AAE3D,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `base64url` interop shim.
|
|
3
|
+
*
|
|
4
|
+
* The `base64url` package ships ESM-style type declarations
|
|
5
|
+
* (`export default base64url`) over a CommonJS runtime. Under NodeNext module
|
|
6
|
+
* resolution the default import is typed as the module namespace object rather
|
|
7
|
+
* than the callable `Base64Url`, so both calling it (`base64url(...)`) and
|
|
8
|
+
* member access (`base64url.toBuffer(...)`) fail to type-check. At runtime
|
|
9
|
+
* `esModuleInterop` already yields the callable, so this is a type-only
|
|
10
|
+
* correction, centralized here rather than repeated at every call site.
|
|
11
|
+
*
|
|
12
|
+
* Every module in the kit imports base64url from here, never directly from the
|
|
13
|
+
* package, so the interop fix lives in exactly one place.
|
|
14
|
+
*/
|
|
15
|
+
import base64urlDefault from "base64url";
|
|
16
|
+
const base64url = base64urlDefault;
|
|
17
|
+
export default base64url;
|
|
18
|
+
//# sourceMappingURL=base64url.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64url.js","sourceRoot":"","sources":["../src/base64url.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,gBAAoC,MAAM,WAAW,CAAC;AAE7D,MAAM,SAAS,GAAG,gBAAwC,CAAC;AAE3D,eAAe,SAAS,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constants used throughout the Passkey Kit SDK.
|
|
3
|
+
*
|
|
4
|
+
* Cryptographic sizes mirror the smart-wallet contract; the deployer seed is
|
|
5
|
+
* load-bearing for deterministic contract-id derivation (see below).
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
/** Size of an uncompressed secp256r1 (P-256) public key, in bytes. */
|
|
10
|
+
export declare const SECP256R1_PUBLIC_KEY_SIZE = 65;
|
|
11
|
+
/** First byte of an uncompressed secp256r1 public key (0x04). */
|
|
12
|
+
export declare const UNCOMPRESSED_PUBKEY_PREFIX = 4;
|
|
13
|
+
/** Size of an Ed25519 public key, in bytes. */
|
|
14
|
+
export declare const ED25519_PUBLIC_KEY_SIZE = 32;
|
|
15
|
+
/** Size of an Ed25519 signature, in bytes. */
|
|
16
|
+
export declare const ED25519_SIGNATURE_SIZE = 64;
|
|
17
|
+
/**
|
|
18
|
+
* Order (n) of the secp256r1 (P-256) curve, used to enforce low-S signatures.
|
|
19
|
+
* @see https://github.com/stellar/stellar-protocol/discussions/1435
|
|
20
|
+
*/
|
|
21
|
+
export declare const SECP256R1_CURVE_ORDER: bigint;
|
|
22
|
+
/** Field prime (p) of the secp256r1 (P-256) curve. */
|
|
23
|
+
export declare const SECP256R1_FIELD_PRIME: bigint;
|
|
24
|
+
/** Curve coefficient `b` of secp256r1 (P-256): y² = x³ − 3x + b (mod p). */
|
|
25
|
+
export declare const SECP256R1_B: bigint;
|
|
26
|
+
/** Default timeout for WebAuthn ceremonies, in milliseconds. */
|
|
27
|
+
export declare const WEBAUTHN_TIMEOUT_MS = 60000;
|
|
28
|
+
/** Length, in bytes, of a randomly generated WebAuthn challenge. */
|
|
29
|
+
export declare const WEBAUTHN_CHALLENGE_SIZE = 32;
|
|
30
|
+
/**
|
|
31
|
+
* Seed for the default (deterministic) deployer keypair.
|
|
32
|
+
*
|
|
33
|
+
* The deployer keypair is derived as
|
|
34
|
+
* `Keypair.fromRawEd25519Seed(sha256(utf8(DEFAULT_DEPLOYER_SEED)))`. Deriving it
|
|
35
|
+
* from a fixed, well-known string makes smart-wallet contract IDs reproducible
|
|
36
|
+
* across clients from a passkey credential ID alone (`salt = sha256(keyId)`,
|
|
37
|
+
* `deployer = this keypair`), which is exactly what the indexer reverse-lookup
|
|
38
|
+
* (keyId → contract) depends on.
|
|
39
|
+
*
|
|
40
|
+
* This value MUST remain `"kalepail"`: every wallet ever deployed by passkey-kit
|
|
41
|
+
* used this deployer, and the derivation is load-bearing for discovery. The
|
|
42
|
+
* deployer only pays fees and salts the deploy — it never controls the wallet —
|
|
43
|
+
* but it IS a shared, publicly-derivable keypair. Provide your own
|
|
44
|
+
* `deploySource` secret for a dedicated fee payer (note: a different deployer
|
|
45
|
+
* changes the derived contract addresses and breaks keyId → contract discovery).
|
|
46
|
+
*/
|
|
47
|
+
export declare const DEFAULT_DEPLOYER_SEED = "kalepail";
|
|
48
|
+
/**
|
|
49
|
+
* Default transaction timeout, in seconds.
|
|
50
|
+
*
|
|
51
|
+
* The OpenZeppelin Relayer requires a time-bound of <= 30s on submitted
|
|
52
|
+
* transactions, so the kit defaults to that.
|
|
53
|
+
*/
|
|
54
|
+
export declare const DEFAULT_TIMEOUT_SECONDS = 30;
|
|
55
|
+
/** Default IndexedDB database name for passkey credential storage. */
|
|
56
|
+
export declare const DB_NAME = "passkey-kit";
|
|
57
|
+
/** Current IndexedDB schema version. */
|
|
58
|
+
export declare const DB_VERSION = 1;
|
|
59
|
+
/** IndexedDB object-store name for passkey credentials. */
|
|
60
|
+
export declare const IDB_STORE_CREDENTIALS = "credentials";
|
|
61
|
+
/** IndexedDB index name for contract-id lookups. */
|
|
62
|
+
export declare const IDB_INDEX_CONTRACT_ID = "contractId";
|
|
63
|
+
/** localStorage key under which passkey credentials are persisted. */
|
|
64
|
+
export declare const LOCALSTORAGE_CREDENTIALS_KEY = "passkey-kit:credentials";
|
|
65
|
+
/**
|
|
66
|
+
* Default relayer request timeout, in milliseconds (6 minutes).
|
|
67
|
+
*
|
|
68
|
+
* Long enough to absorb testnet channel-account funding retries after a network
|
|
69
|
+
* reset. Mainnet requests return quickly; this only bounds the maximum wait.
|
|
70
|
+
*/
|
|
71
|
+
export declare const DEFAULT_RELAYER_TIMEOUT_MS = 360000;
|
|
72
|
+
/** OpenZeppelin managed Channels relayer endpoint (mainnet). */
|
|
73
|
+
export declare const CHANNELS_MAINNET_URL = "https://channels.openzeppelin.com";
|
|
74
|
+
/** OpenZeppelin managed Channels relayer endpoint (testnet). */
|
|
75
|
+
export declare const CHANNELS_TESTNET_URL = "https://channels.openzeppelin.com/testnet";
|
|
76
|
+
/** Default indexer request timeout, in milliseconds. */
|
|
77
|
+
export declare const DEFAULT_INDEXER_TIMEOUT_MS = 10000;
|
|
78
|
+
/**
|
|
79
|
+
* Mercury's hosted, keyless passkey-indexer base URLs, per network. Public REST
|
|
80
|
+
* (no API key / JWT); covers both the legacy `("sw_v1", …)` and v1
|
|
81
|
+
* `#[contractevent]` signer generations with full history.
|
|
82
|
+
*
|
|
83
|
+
* @see https://docs.mercurydata.app/smart-wallet-indexers/introduction-1
|
|
84
|
+
*/
|
|
85
|
+
export declare const MERCURY_PASSKEY_INDEXER_URLS: {
|
|
86
|
+
readonly testnet: "https://testnet.mercurydata.app/rest/passkey-indexer";
|
|
87
|
+
readonly mainnet: "https://mainnet.mercurydata.app/rest/passkey-indexer";
|
|
88
|
+
};
|
|
89
|
+
/** Stellar Friendbot URL for testnet funding. */
|
|
90
|
+
export declare const FRIENDBOT_URL = "https://friendbot.stellar.org";
|
|
91
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,sEAAsE;AACtE,eAAO,MAAM,yBAAyB,KAAK,CAAC;AAE5C,iEAAiE;AACjE,eAAO,MAAM,0BAA0B,IAAO,CAAC;AAE/C,+CAA+C;AAC/C,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAE1C,8CAA8C;AAC9C,eAAO,MAAM,sBAAsB,KAAK,CAAC;AAEzC;;;GAGG;AACH,eAAO,MAAM,qBAAqB,QAEjC,CAAC;AAEF,sDAAsD;AACtD,eAAO,MAAM,qBAAqB,QAEjC,CAAC;AAEF,4EAA4E;AAC5E,eAAO,MAAM,WAAW,QAEvB,CAAC;AAMF,gEAAgE;AAChE,eAAO,MAAM,mBAAmB,QAAS,CAAC;AAE1C,oEAAoE;AACpE,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAM1C;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,qBAAqB,aAAa,CAAC;AAMhD;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAM1C,sEAAsE;AACtE,eAAO,MAAM,OAAO,gBAAgB,CAAC;AAErC,wCAAwC;AACxC,eAAO,MAAM,UAAU,IAAI,CAAC;AAE5B,2DAA2D;AAC3D,eAAO,MAAM,qBAAqB,gBAAgB,CAAC;AAEnD,oDAAoD;AACpD,eAAO,MAAM,qBAAqB,eAAe,CAAC;AAElD,sEAAsE;AACtE,eAAO,MAAM,4BAA4B,4BAA4B,CAAC;AAMtE;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,SAAU,CAAC;AAElD,gEAAgE;AAChE,eAAO,MAAM,oBAAoB,sCAAsC,CAAC;AAExE,gEAAgE;AAChE,eAAO,MAAM,oBAAoB,8CAA8C,CAAC;AAMhF,wDAAwD;AACxD,eAAO,MAAM,0BAA0B,QAAS,CAAC;AAEjD;;;;;;GAMG;AACH,eAAO,MAAM,4BAA4B;;;CAG/B,CAAC;AAMX,iDAAiD;AACjD,eAAO,MAAM,aAAa,kCAAkC,CAAC"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constants used throughout the Passkey Kit SDK.
|
|
3
|
+
*
|
|
4
|
+
* Cryptographic sizes mirror the smart-wallet contract; the deployer seed is
|
|
5
|
+
* load-bearing for deterministic contract-id derivation (see below).
|
|
6
|
+
*
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
*/
|
|
9
|
+
// ============================================================================
|
|
10
|
+
// Cryptographic constants (mirror the smart-wallet contract)
|
|
11
|
+
// ============================================================================
|
|
12
|
+
/** Size of an uncompressed secp256r1 (P-256) public key, in bytes. */
|
|
13
|
+
export const SECP256R1_PUBLIC_KEY_SIZE = 65;
|
|
14
|
+
/** First byte of an uncompressed secp256r1 public key (0x04). */
|
|
15
|
+
export const UNCOMPRESSED_PUBKEY_PREFIX = 0x04;
|
|
16
|
+
/** Size of an Ed25519 public key, in bytes. */
|
|
17
|
+
export const ED25519_PUBLIC_KEY_SIZE = 32;
|
|
18
|
+
/** Size of an Ed25519 signature, in bytes. */
|
|
19
|
+
export const ED25519_SIGNATURE_SIZE = 64;
|
|
20
|
+
/**
|
|
21
|
+
* Order (n) of the secp256r1 (P-256) curve, used to enforce low-S signatures.
|
|
22
|
+
* @see https://github.com/stellar/stellar-protocol/discussions/1435
|
|
23
|
+
*/
|
|
24
|
+
export const SECP256R1_CURVE_ORDER = BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551");
|
|
25
|
+
/** Field prime (p) of the secp256r1 (P-256) curve. */
|
|
26
|
+
export const SECP256R1_FIELD_PRIME = BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff");
|
|
27
|
+
/** Curve coefficient `b` of secp256r1 (P-256): y² = x³ − 3x + b (mod p). */
|
|
28
|
+
export const SECP256R1_B = BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b");
|
|
29
|
+
// ============================================================================
|
|
30
|
+
// WebAuthn configuration
|
|
31
|
+
// ============================================================================
|
|
32
|
+
/** Default timeout for WebAuthn ceremonies, in milliseconds. */
|
|
33
|
+
export const WEBAUTHN_TIMEOUT_MS = 60_000;
|
|
34
|
+
/** Length, in bytes, of a randomly generated WebAuthn challenge. */
|
|
35
|
+
export const WEBAUTHN_CHALLENGE_SIZE = 32;
|
|
36
|
+
// ============================================================================
|
|
37
|
+
// Deployer
|
|
38
|
+
// ============================================================================
|
|
39
|
+
/**
|
|
40
|
+
* Seed for the default (deterministic) deployer keypair.
|
|
41
|
+
*
|
|
42
|
+
* The deployer keypair is derived as
|
|
43
|
+
* `Keypair.fromRawEd25519Seed(sha256(utf8(DEFAULT_DEPLOYER_SEED)))`. Deriving it
|
|
44
|
+
* from a fixed, well-known string makes smart-wallet contract IDs reproducible
|
|
45
|
+
* across clients from a passkey credential ID alone (`salt = sha256(keyId)`,
|
|
46
|
+
* `deployer = this keypair`), which is exactly what the indexer reverse-lookup
|
|
47
|
+
* (keyId → contract) depends on.
|
|
48
|
+
*
|
|
49
|
+
* This value MUST remain `"kalepail"`: every wallet ever deployed by passkey-kit
|
|
50
|
+
* used this deployer, and the derivation is load-bearing for discovery. The
|
|
51
|
+
* deployer only pays fees and salts the deploy — it never controls the wallet —
|
|
52
|
+
* but it IS a shared, publicly-derivable keypair. Provide your own
|
|
53
|
+
* `deploySource` secret for a dedicated fee payer (note: a different deployer
|
|
54
|
+
* changes the derived contract addresses and breaks keyId → contract discovery).
|
|
55
|
+
*/
|
|
56
|
+
export const DEFAULT_DEPLOYER_SEED = "kalepail";
|
|
57
|
+
// ============================================================================
|
|
58
|
+
// Transaction timeouts
|
|
59
|
+
// ============================================================================
|
|
60
|
+
/**
|
|
61
|
+
* Default transaction timeout, in seconds.
|
|
62
|
+
*
|
|
63
|
+
* The OpenZeppelin Relayer requires a time-bound of <= 30s on submitted
|
|
64
|
+
* transactions, so the kit defaults to that.
|
|
65
|
+
*/
|
|
66
|
+
export const DEFAULT_TIMEOUT_SECONDS = 30;
|
|
67
|
+
// ============================================================================
|
|
68
|
+
// Storage configuration
|
|
69
|
+
// ============================================================================
|
|
70
|
+
/** Default IndexedDB database name for passkey credential storage. */
|
|
71
|
+
export const DB_NAME = "passkey-kit";
|
|
72
|
+
/** Current IndexedDB schema version. */
|
|
73
|
+
export const DB_VERSION = 1;
|
|
74
|
+
/** IndexedDB object-store name for passkey credentials. */
|
|
75
|
+
export const IDB_STORE_CREDENTIALS = "credentials";
|
|
76
|
+
/** IndexedDB index name for contract-id lookups. */
|
|
77
|
+
export const IDB_INDEX_CONTRACT_ID = "contractId";
|
|
78
|
+
/** localStorage key under which passkey credentials are persisted. */
|
|
79
|
+
export const LOCALSTORAGE_CREDENTIALS_KEY = "passkey-kit:credentials";
|
|
80
|
+
// ============================================================================
|
|
81
|
+
// Relayer
|
|
82
|
+
// ============================================================================
|
|
83
|
+
/**
|
|
84
|
+
* Default relayer request timeout, in milliseconds (6 minutes).
|
|
85
|
+
*
|
|
86
|
+
* Long enough to absorb testnet channel-account funding retries after a network
|
|
87
|
+
* reset. Mainnet requests return quickly; this only bounds the maximum wait.
|
|
88
|
+
*/
|
|
89
|
+
export const DEFAULT_RELAYER_TIMEOUT_MS = 360_000;
|
|
90
|
+
/** OpenZeppelin managed Channels relayer endpoint (mainnet). */
|
|
91
|
+
export const CHANNELS_MAINNET_URL = "https://channels.openzeppelin.com";
|
|
92
|
+
/** OpenZeppelin managed Channels relayer endpoint (testnet). */
|
|
93
|
+
export const CHANNELS_TESTNET_URL = "https://channels.openzeppelin.com/testnet";
|
|
94
|
+
// ============================================================================
|
|
95
|
+
// Indexer
|
|
96
|
+
// ============================================================================
|
|
97
|
+
/** Default indexer request timeout, in milliseconds. */
|
|
98
|
+
export const DEFAULT_INDEXER_TIMEOUT_MS = 10_000;
|
|
99
|
+
/**
|
|
100
|
+
* Mercury's hosted, keyless passkey-indexer base URLs, per network. Public REST
|
|
101
|
+
* (no API key / JWT); covers both the legacy `("sw_v1", …)` and v1
|
|
102
|
+
* `#[contractevent]` signer generations with full history.
|
|
103
|
+
*
|
|
104
|
+
* @see https://docs.mercurydata.app/smart-wallet-indexers/introduction-1
|
|
105
|
+
*/
|
|
106
|
+
export const MERCURY_PASSKEY_INDEXER_URLS = {
|
|
107
|
+
testnet: "https://testnet.mercurydata.app/rest/passkey-indexer",
|
|
108
|
+
mainnet: "https://mainnet.mercurydata.app/rest/passkey-indexer",
|
|
109
|
+
};
|
|
110
|
+
// ============================================================================
|
|
111
|
+
// Networks
|
|
112
|
+
// ============================================================================
|
|
113
|
+
/** Stellar Friendbot URL for testnet funding. */
|
|
114
|
+
export const FRIENDBOT_URL = "https://friendbot.stellar.org";
|
|
115
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,+EAA+E;AAC/E,6DAA6D;AAC7D,+EAA+E;AAE/E,sEAAsE;AACtE,MAAM,CAAC,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAE5C,iEAAiE;AACjE,MAAM,CAAC,MAAM,0BAA0B,GAAG,IAAI,CAAC;AAE/C,+CAA+C;AAC/C,MAAM,CAAC,MAAM,uBAAuB,GAAG,EAAE,CAAC;AAE1C,8CAA8C;AAC9C,MAAM,CAAC,MAAM,sBAAsB,GAAG,EAAE,CAAC;AAEzC;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CACzC,oEAAoE,CACrE,CAAC;AAEF,sDAA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;AAE/E,wDAAwD;AACxD,MAAM,CAAC,MAAM,0BAA0B,GAAG,MAAM,CAAC;AAEjD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG;IAC1C,OAAO,EAAE,sDAAsD;IAC/D,OAAO,EAAE,sDAAsD;CACvD,CAAC;AAEX,+EAA+E;AAC/E,WAAW;AACX,+EAA+E;AAE/E,iDAAiD;AACjD,MAAM,CAAC,MAAM,aAAa,GAAG,+BAA+B,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contract error decoding.
|
|
3
|
+
*
|
|
4
|
+
* Maps on-chain smart-wallet failure codes (surfaced in simulation/submission
|
|
5
|
+
* diagnostics as `Error(Contract, #N)`) to typed {@link ContractError}s with the
|
|
6
|
+
* enum variant name and a human-readable message.
|
|
7
|
+
*
|
|
8
|
+
* The `SmartWallet` family is the source of truth in the generated bindings'
|
|
9
|
+
* `Errors` map; `contract-errors.test.ts` asserts this registry stays in sync
|
|
10
|
+
* with it, so a bindings regen surfaces any drift.
|
|
11
|
+
*
|
|
12
|
+
* The v1 contract deliberately renumbered its error space to 100-129 so it is
|
|
13
|
+
* disjoint from the legacy (pre-1.0) 1-9 range: a decoded code < 100 means the
|
|
14
|
+
* client is talking to a legacy wallet. Both ranges are kept here so errors
|
|
15
|
+
* from legacy deployed wallets still decode (family `SmartWalletLegacy`).
|
|
16
|
+
*
|
|
17
|
+
* @packageDocumentation
|
|
18
|
+
*/
|
|
19
|
+
import { ContractError, PasskeyKitError } from "./errors.js";
|
|
20
|
+
import type { TransactionFailure } from "./types.js";
|
|
21
|
+
/**
|
|
22
|
+
* Contract families that expose custom error codes.
|
|
23
|
+
*/
|
|
24
|
+
export type ContractErrorFamily = "SmartWallet" | "SmartWalletLegacy";
|
|
25
|
+
/**
|
|
26
|
+
* A single contract error entry: code, enum variant name, family, and a
|
|
27
|
+
* human-readable message.
|
|
28
|
+
*/
|
|
29
|
+
export interface ContractErrorInfo {
|
|
30
|
+
code: number;
|
|
31
|
+
name: string;
|
|
32
|
+
family: ContractErrorFamily;
|
|
33
|
+
message: string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Registry of every known contract error code, keyed by numeric code.
|
|
37
|
+
*/
|
|
38
|
+
export declare const CONTRACT_ERROR_REGISTRY: Readonly<Record<number, ContractErrorInfo>>;
|
|
39
|
+
/**
|
|
40
|
+
* Build a {@link ContractError} for a known contract code, or `null` if the code
|
|
41
|
+
* is not in the registry.
|
|
42
|
+
*/
|
|
43
|
+
export declare function contractErrorFromCode(code: number, context?: Record<string, unknown>): ContractError | null;
|
|
44
|
+
/**
|
|
45
|
+
* Decode a simulation/submission diagnostic into a typed {@link ContractError}.
|
|
46
|
+
*
|
|
47
|
+
* Scans the (stringified) diagnostic for an `Error(Contract, #N)` marker and
|
|
48
|
+
* looks the code up in {@link CONTRACT_ERROR_REGISTRY}. Returns `null` when no
|
|
49
|
+
* contract code is present or the code is unknown, letting callers fall back to
|
|
50
|
+
* a generic {@link SimulationError}/{@link SubmissionError}.
|
|
51
|
+
*/
|
|
52
|
+
export declare function decodeContractError(diagnostic: unknown): ContractError | null;
|
|
53
|
+
/**
|
|
54
|
+
* Build a {@link TransactionFailure} from an already-typed error.
|
|
55
|
+
*/
|
|
56
|
+
export declare function failedTransaction(error: PasskeyKitError, hash?: string): TransactionFailure;
|
|
57
|
+
/**
|
|
58
|
+
* Build a {@link TransactionFailure} from a simulation diagnostic, decoding a
|
|
59
|
+
* contract error when present and otherwise wrapping it in a
|
|
60
|
+
* {@link SimulationError}.
|
|
61
|
+
*/
|
|
62
|
+
export declare function simulationFailure(diagnostic: unknown, hash?: string): TransactionFailure;
|
|
63
|
+
/**
|
|
64
|
+
* Build a {@link TransactionFailure} from a submission diagnostic, decoding a
|
|
65
|
+
* contract error when present and otherwise wrapping it in a
|
|
66
|
+
* {@link SubmissionError}.
|
|
67
|
+
*/
|
|
68
|
+
export declare function submissionFailure(diagnostic: unknown, hash?: string): TransactionFailure;
|
|
69
|
+
//# sourceMappingURL=contract-errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract-errors.d.ts","sourceRoot":"","sources":["../src/contract-errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EACL,aAAa,EAGb,eAAe,EAChB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,aAAa,GAAG,mBAAmB,CAAC;AAEtE;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,mBAAmB,CAAC;IAC5B,OAAO,EAAE,MAAM,CAAC;CACjB;AAWD;;GAEG;AACH,eAAO,MAAM,uBAAuB,EAAE,QAAQ,CAC5C,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAiClC,CAAC;AAkBF;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAChC,aAAa,GAAG,IAAI,CAMtB;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,OAAO,GAAG,aAAa,GAAG,IAAI,CAM7E;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,eAAe,EACtB,IAAI,CAAC,EAAE,MAAM,GACZ,kBAAkB,CAMpB;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,OAAO,EACnB,IAAI,CAAC,EAAE,MAAM,GACZ,kBAAkB,CAKpB;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,OAAO,EACnB,IAAI,CAAC,EAAE,MAAM,GACZ,kBAAkB,CAQpB"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Contract error decoding.
|
|
3
|
+
*
|
|
4
|
+
* Maps on-chain smart-wallet failure codes (surfaced in simulation/submission
|
|
5
|
+
* diagnostics as `Error(Contract, #N)`) to typed {@link ContractError}s with the
|
|
6
|
+
* enum variant name and a human-readable message.
|
|
7
|
+
*
|
|
8
|
+
* The `SmartWallet` family is the source of truth in the generated bindings'
|
|
9
|
+
* `Errors` map; `contract-errors.test.ts` asserts this registry stays in sync
|
|
10
|
+
* with it, so a bindings regen surfaces any drift.
|
|
11
|
+
*
|
|
12
|
+
* The v1 contract deliberately renumbered its error space to 100-129 so it is
|
|
13
|
+
* disjoint from the legacy (pre-1.0) 1-9 range: a decoded code < 100 means the
|
|
14
|
+
* client is talking to a legacy wallet. Both ranges are kept here so errors
|
|
15
|
+
* from legacy deployed wallets still decode (family `SmartWalletLegacy`).
|
|
16
|
+
*
|
|
17
|
+
* @packageDocumentation
|
|
18
|
+
*/
|
|
19
|
+
import { ContractError, SimulationError, SubmissionError, } from "./errors.js";
|
|
20
|
+
function entry(code, name, family, message) {
|
|
21
|
+
return [code, { code, name, family, message }];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Registry of every known contract error code, keyed by numeric code.
|
|
25
|
+
*/
|
|
26
|
+
export const CONTRACT_ERROR_REGISTRY = Object.freeze(Object.fromEntries([
|
|
27
|
+
// --- v1 SmartWallet (100-129) — source of truth in the bindings Errors map ---
|
|
28
|
+
// 100-109: signer storage / management
|
|
29
|
+
entry(100, "SignerNotFound", "SmartWallet", "The requested signer does not exist on this smart wallet."),
|
|
30
|
+
entry(101, "SignerAlreadyExists", "SmartWallet", "add_signer was called with a signer key that already exists."),
|
|
31
|
+
entry(102, "SignerExpired", "SmartWallet", "The signer's expiration timestamp is in the past."),
|
|
32
|
+
entry(103, "LastAdminSigner", "SmartWallet", "This change would remove or demote the wallet's last durable admin signer (persistent, non-expiring, independently admin-capable) and permanently lock the wallet's admin surface; add or promote a replacement admin signer first."),
|
|
33
|
+
entry(104, "LastSigner", "SmartWallet", "The operation would leave the wallet without any durable (Persistent, non-expiring) signer — thrown by remove_signer, update_signer demotions, and a __constructor with a non-durable first signer; keep or add a Persistent, non-expiring signer."),
|
|
34
|
+
// 110-119: auth (__check_auth)
|
|
35
|
+
entry(110, "MissingContext", "SmartWallet", "No signer in the signatures map is permitted to authorize one of the requested auth contexts."),
|
|
36
|
+
entry(111, "SignatureKeyValueMismatch", "SmartWallet", "A signature's variant does not match the stored signer it claims to be for."),
|
|
37
|
+
// 120-129: WebAuthn (secp256r1) verification
|
|
38
|
+
entry(120, "ClientDataJsonTooLarge", "SmartWallet", "clientDataJSON exceeds the 1024-byte parse buffer."),
|
|
39
|
+
entry(121, "ClientDataJsonParseError", "SmartWallet", "clientDataJSON is not parseable JSON (or is missing required fields)."),
|
|
40
|
+
entry(122, "ClientDataJsonChallengeIncorrect", "SmartWallet", "The clientDataJSON challenge does not match the signature payload; this binding MUST NOT be weakened."),
|
|
41
|
+
entry(123, "InvalidWebAuthnType", "SmartWallet", 'clientDataJSON `type` is not "webauthn.get".'),
|
|
42
|
+
entry(124, "InvalidAuthenticatorData", "SmartWallet", "authenticatorData is shorter than the WebAuthn minimum of 37 bytes."),
|
|
43
|
+
entry(125, "UserPresenceRequired", "SmartWallet", "The authenticator did not set the User Present (UP) flag."),
|
|
44
|
+
entry(126, "AuthenticatorDataTooLarge", "SmartWallet", "authenticatorData exceeds the 1024-byte cap."),
|
|
45
|
+
// --- Legacy (pre-1.0) 1-9 — kept so errors from legacy deployed wallets decode ---
|
|
46
|
+
entry(1, "NotFound", "SmartWalletLegacy", "[legacy] The specified signer was not found."),
|
|
47
|
+
entry(2, "AlreadyExists", "SmartWalletLegacy", "[legacy] The signer already exists on this wallet."),
|
|
48
|
+
entry(3, "MissingContext", "SmartWalletLegacy", "[legacy] The signature did not cover a required authorization context."),
|
|
49
|
+
entry(4, "SignerExpired", "SmartWalletLegacy", "[legacy] The signer has expired."),
|
|
50
|
+
entry(5, "FailedSignerLimits", "SmartWalletLegacy", "[legacy] The signer is not permitted to authorize this context by its limits."),
|
|
51
|
+
entry(6, "FailedPolicySignerLimits", "SmartWalletLegacy", "[legacy] A policy signer's limits rejected this context."),
|
|
52
|
+
entry(7, "SignatureKeyValueMismatch", "SmartWalletLegacy", "[legacy] A signature entry's key and value did not match."),
|
|
53
|
+
entry(8, "ClientDataJsonChallengeIncorrect", "SmartWalletLegacy", "[legacy] The WebAuthn clientDataJSON challenge did not match the signature payload."),
|
|
54
|
+
entry(9, "JsonParseError", "SmartWalletLegacy", "[legacy] The WebAuthn clientDataJSON could not be parsed."),
|
|
55
|
+
]));
|
|
56
|
+
/**
|
|
57
|
+
* Matches the host's rendering of a contract error, e.g. `Error(Contract, #4)`.
|
|
58
|
+
*/
|
|
59
|
+
const CONTRACT_ERROR_PATTERN = /Error\(Contract,\s*#(\d+)\)/;
|
|
60
|
+
function diagnosticToString(diagnostic) {
|
|
61
|
+
if (diagnostic == null)
|
|
62
|
+
return "";
|
|
63
|
+
if (typeof diagnostic === "string")
|
|
64
|
+
return diagnostic;
|
|
65
|
+
if (diagnostic instanceof Error)
|
|
66
|
+
return diagnostic.message;
|
|
67
|
+
try {
|
|
68
|
+
return JSON.stringify(diagnostic);
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return String(diagnostic);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Build a {@link ContractError} for a known contract code, or `null` if the code
|
|
76
|
+
* is not in the registry.
|
|
77
|
+
*/
|
|
78
|
+
export function contractErrorFromCode(code, context) {
|
|
79
|
+
const info = CONTRACT_ERROR_REGISTRY[code];
|
|
80
|
+
if (!info)
|
|
81
|
+
return null;
|
|
82
|
+
return new ContractError(info.code, info.name, info.family, info.message, {
|
|
83
|
+
context,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Decode a simulation/submission diagnostic into a typed {@link ContractError}.
|
|
88
|
+
*
|
|
89
|
+
* Scans the (stringified) diagnostic for an `Error(Contract, #N)` marker and
|
|
90
|
+
* looks the code up in {@link CONTRACT_ERROR_REGISTRY}. Returns `null` when no
|
|
91
|
+
* contract code is present or the code is unknown, letting callers fall back to
|
|
92
|
+
* a generic {@link SimulationError}/{@link SubmissionError}.
|
|
93
|
+
*/
|
|
94
|
+
export function decodeContractError(diagnostic) {
|
|
95
|
+
const text = diagnosticToString(diagnostic);
|
|
96
|
+
const match = text.match(CONTRACT_ERROR_PATTERN);
|
|
97
|
+
if (!match)
|
|
98
|
+
return null;
|
|
99
|
+
const code = Number.parseInt(match[1], 10);
|
|
100
|
+
return contractErrorFromCode(code, { diagnostic: text });
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Build a {@link TransactionFailure} from an already-typed error.
|
|
104
|
+
*/
|
|
105
|
+
export function failedTransaction(error, hash) {
|
|
106
|
+
return {
|
|
107
|
+
success: false,
|
|
108
|
+
error,
|
|
109
|
+
...(hash ? { hash } : {}),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Build a {@link TransactionFailure} from a simulation diagnostic, decoding a
|
|
114
|
+
* contract error when present and otherwise wrapping it in a
|
|
115
|
+
* {@link SimulationError}.
|
|
116
|
+
*/
|
|
117
|
+
export function simulationFailure(diagnostic, hash) {
|
|
118
|
+
const error = decodeContractError(diagnostic) ??
|
|
119
|
+
new SimulationError(diagnosticToString(diagnostic) || "Simulation failed");
|
|
120
|
+
return failedTransaction(error, hash);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Build a {@link TransactionFailure} from a submission diagnostic, decoding a
|
|
124
|
+
* contract error when present and otherwise wrapping it in a
|
|
125
|
+
* {@link SubmissionError}.
|
|
126
|
+
*/
|
|
127
|
+
export function submissionFailure(diagnostic, hash) {
|
|
128
|
+
const error = decodeContractError(diagnostic) ??
|
|
129
|
+
new SubmissionError(diagnosticToString(diagnostic) || "Submission failed", hash);
|
|
130
|
+
return failedTransaction(error, hash);
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=contract-errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract-errors.js","sourceRoot":"","sources":["../src/contract-errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EACL,aAAa,EACb,eAAe,EACf,eAAe,GAEhB,MAAM,aAAa,CAAC;AAmBrB,SAAS,KAAK,CACZ,IAAY,EACZ,IAAY,EACZ,MAA2B,EAC3B,OAAe;IAEf,OAAO,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;AACjD,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAEhC,MAAM,CAAC,MAAM,CACf,MAAM,CAAC,WAAW,CAAC;IACjB,gFAAgF;IAChF,uCAAuC;IACvC,KAAK,CAAC,GAAG,EAAE,gBAAgB,EAAE,aAAa,EAAE,2DAA2D,CAAC;IACxG,KAAK,CAAC,GAAG,EAAE,qBAAqB,EAAE,aAAa,EAAE,8DAA8D,CAAC;IAChH,KAAK,CAAC,GAAG,EAAE,eAAe,EAAE,aAAa,EAAE,mDAAmD,CAAC;IAC/F,KAAK,CAAC,GAAG,EAAE,iBAAiB,EAAE,aAAa,EAAE,qOAAqO,CAAC;IACnR,KAAK,CAAC,GAAG,EAAE,YAAY,EAAE,aAAa,EAAE,oPAAoP,CAAC;IAC7R,+BAA+B;IAC/B,KAAK,CAAC,GAAG,EAAE,gBAAgB,EAAE,aAAa,EAAE,+FAA+F,CAAC;IAC5I,KAAK,CAAC,GAAG,EAAE,2BAA2B,EAAE,aAAa,EAAE,6EAA6E,CAAC;IACrI,6CAA6C;IAC7C,KAAK,CAAC,GAAG,EAAE,wBAAwB,EAAE,aAAa,EAAE,o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