@turnkey/core 1.0.0-beta.2 → 1.0.0-beta.5
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/dist/__clients__/core.d.ts +92 -9
- package/dist/__clients__/core.d.ts.map +1 -1
- package/dist/__clients__/core.js +699 -535
- package/dist/__clients__/core.js.map +1 -1
- package/dist/__clients__/core.mjs +702 -538
- package/dist/__clients__/core.mjs.map +1 -1
- package/dist/__generated__/sdk-client-base.d.ts +1 -1
- package/dist/__generated__/sdk-client-base.d.ts.map +1 -1
- package/dist/__generated__/sdk-client-base.js +156 -253
- package/dist/__generated__/sdk-client-base.js.map +1 -1
- package/dist/__generated__/sdk-client-base.mjs +156 -253
- package/dist/__generated__/sdk-client-base.mjs.map +1 -1
- package/dist/__generated__/version.d.ts +1 -1
- package/dist/__generated__/version.js +1 -1
- package/dist/__generated__/version.mjs +1 -1
- package/dist/__inputs__/public_api.types.d.ts +377 -504
- package/dist/__inputs__/public_api.types.d.ts.map +1 -1
- package/dist/__types__/base.d.ts +193 -75
- package/dist/__types__/base.d.ts.map +1 -1
- package/dist/__types__/base.js +14 -13
- package/dist/__types__/base.js.map +1 -1
- package/dist/__types__/base.mjs +15 -14
- package/dist/__types__/base.mjs.map +1 -1
- package/dist/__wallet__/base.d.ts +11 -0
- package/dist/__wallet__/base.d.ts.map +1 -1
- package/dist/__wallet__/base.js +12 -1
- package/dist/__wallet__/base.js.map +1 -1
- package/dist/__wallet__/base.mjs +12 -1
- package/dist/__wallet__/base.mjs.map +1 -1
- package/dist/__wallet__/connector.d.ts +31 -4
- package/dist/__wallet__/connector.d.ts.map +1 -1
- package/dist/__wallet__/connector.js +35 -5
- package/dist/__wallet__/connector.js.map +1 -1
- package/dist/__wallet__/connector.mjs +35 -5
- package/dist/__wallet__/connector.mjs.map +1 -1
- package/dist/__wallet__/mobile/manager.d.ts +21 -5
- package/dist/__wallet__/mobile/manager.d.ts.map +1 -1
- package/dist/__wallet__/mobile/manager.js +28 -11
- package/dist/__wallet__/mobile/manager.js.map +1 -1
- package/dist/__wallet__/mobile/manager.mjs +28 -11
- package/dist/__wallet__/mobile/manager.mjs.map +1 -1
- package/dist/__wallet__/stamper.d.ts +73 -2
- package/dist/__wallet__/stamper.d.ts.map +1 -1
- package/dist/__wallet__/stamper.js +81 -15
- package/dist/__wallet__/stamper.js.map +1 -1
- package/dist/__wallet__/stamper.mjs +82 -16
- package/dist/__wallet__/stamper.mjs.map +1 -1
- package/dist/__wallet__/wallet-connect/base.d.ts +102 -19
- package/dist/__wallet__/wallet-connect/base.d.ts.map +1 -1
- package/dist/__wallet__/wallet-connect/base.js +198 -77
- package/dist/__wallet__/wallet-connect/base.js.map +1 -1
- package/dist/__wallet__/wallet-connect/base.mjs +198 -77
- package/dist/__wallet__/wallet-connect/base.mjs.map +1 -1
- package/dist/__wallet__/wallet-connect/client.d.ts +50 -17
- package/dist/__wallet__/wallet-connect/client.d.ts.map +1 -1
- package/dist/__wallet__/wallet-connect/client.js +76 -19
- package/dist/__wallet__/wallet-connect/client.js.map +1 -1
- package/dist/__wallet__/wallet-connect/client.mjs +76 -19
- package/dist/__wallet__/wallet-connect/client.mjs.map +1 -1
- package/dist/__wallet__/web/manager.d.ts +20 -12
- package/dist/__wallet__/web/manager.d.ts.map +1 -1
- package/dist/__wallet__/web/manager.js +29 -21
- package/dist/__wallet__/web/manager.js.map +1 -1
- package/dist/__wallet__/web/manager.mjs +29 -21
- package/dist/__wallet__/web/manager.mjs.map +1 -1
- package/dist/__wallet__/web/native/ethereum.d.ts +45 -11
- package/dist/__wallet__/web/native/ethereum.d.ts.map +1 -1
- package/dist/__wallet__/web/native/ethereum.js +58 -17
- package/dist/__wallet__/web/native/ethereum.js.map +1 -1
- package/dist/__wallet__/web/native/ethereum.mjs +58 -17
- package/dist/__wallet__/web/native/ethereum.mjs.map +1 -1
- package/dist/__wallet__/web/native/solana.d.ts +56 -3
- package/dist/__wallet__/web/native/solana.d.ts.map +1 -1
- package/dist/__wallet__/web/native/solana.js +95 -36
- package/dist/__wallet__/web/native/solana.js.map +1 -1
- package/dist/__wallet__/web/native/solana.mjs +95 -36
- package/dist/__wallet__/web/native/solana.mjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/utils.d.ts +59 -13
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +105 -30
- package/dist/utils.js.map +1 -1
- package/dist/utils.mjs +103 -29
- package/dist/utils.mjs.map +1 -1
- package/package.json +8 -8
|
@@ -8,7 +8,12 @@ class MobileWalletManager {
|
|
|
8
8
|
/**
|
|
9
9
|
* Constructs a MobileWalletManager that only uses WalletConnect.
|
|
10
10
|
*
|
|
11
|
-
*
|
|
11
|
+
* - Determines enabled chains based on provided namespaces for Ethereum and Solana.
|
|
12
|
+
* - Initializes WalletConnect wallet interface and maps it to supported chains.
|
|
13
|
+
* - Optionally enables stamping and connecting flows based on feature flags that live in the cfg.
|
|
14
|
+
* - Sets up `CrossPlatformWalletStamper` and `CrossPlatformWalletConnector` if auth or connecting features are enabled.
|
|
15
|
+
*
|
|
16
|
+
* @param cfg - Wallet manager configuration (we only use WalletConnect fields).
|
|
12
17
|
*/
|
|
13
18
|
constructor(cfg) {
|
|
14
19
|
// queue of async initialization functions
|
|
@@ -18,12 +23,15 @@ class MobileWalletManager {
|
|
|
18
23
|
// maps a blockchain chain to its corresponding wallet interface types
|
|
19
24
|
this.chainToInterfaces = {};
|
|
20
25
|
/**
|
|
21
|
-
* Registers a wallet interface as supporting a specific blockchain chain.
|
|
26
|
+
* Registers a wallet interface type as supporting a specific blockchain chain.
|
|
27
|
+
*
|
|
28
|
+
* @param chain - Chain (e.g., Ethereum, Solana).
|
|
29
|
+
* @param interfaceType - Wallet interface type to associate with the chain.
|
|
22
30
|
*/
|
|
23
|
-
this.addChainInterface = (chain,
|
|
31
|
+
this.addChainInterface = (chain, interfaceType) => {
|
|
24
32
|
if (!this.chainToInterfaces[chain])
|
|
25
33
|
this.chainToInterfaces[chain] = [];
|
|
26
|
-
this.chainToInterfaces[chain].push(
|
|
34
|
+
this.chainToInterfaces[chain].push(interfaceType);
|
|
27
35
|
};
|
|
28
36
|
const ethereumNamespaces = cfg.chains.ethereum?.walletConnectNamespaces ?? [];
|
|
29
37
|
const solanaNamespaces = cfg.chains.solana?.walletConnectNamespaces ?? [];
|
|
@@ -52,30 +60,39 @@ class MobileWalletManager {
|
|
|
52
60
|
}
|
|
53
61
|
}
|
|
54
62
|
/**
|
|
55
|
-
* Initializes
|
|
63
|
+
* Initializes WalletConnect components and any registered wallet interfaces.
|
|
64
|
+
*
|
|
65
|
+
* - First initializes the low-level WalletConnect client with the provided config.
|
|
66
|
+
* - Then initializes higher-level wallet interface `WalletConnectWallet` using registered async initializers.
|
|
56
67
|
*
|
|
57
|
-
* @param cfg - Wallet manager configuration.
|
|
68
|
+
* @param cfg - Wallet manager configuration used for initializing the WalletConnect client.
|
|
58
69
|
*/
|
|
59
70
|
async init(cfg) {
|
|
60
71
|
if (this.wcClient) {
|
|
61
72
|
await this.wcClient.init(cfg.walletConnect);
|
|
62
73
|
}
|
|
74
|
+
// we initialize the high-level WalletConnectWallet
|
|
75
|
+
// we do this because we can't init this inside the constructor since it's async
|
|
63
76
|
await Promise.all(this.initializers.map((fn) => fn()));
|
|
64
|
-
await this.stamper?.init();
|
|
65
77
|
}
|
|
66
78
|
/**
|
|
67
79
|
* Retrieves available wallet providers, optionally filtered by chain.
|
|
68
80
|
*
|
|
81
|
+
* - If a chain is specified, filters wallet interfaces that support that chain.
|
|
82
|
+
* - Aggregates providers across all registered wallet interfaces.
|
|
83
|
+
* - Filters WalletConnect results to match the specified chain.
|
|
84
|
+
*
|
|
69
85
|
* @param chain - Optional chain to filter providers by.
|
|
70
|
-
* @
|
|
86
|
+
* @returns A promise that resolves to an array of `WalletProvider` objects.
|
|
87
|
+
* @throws {Error} If no wallet interface is registered for the given chain.
|
|
71
88
|
*/
|
|
72
89
|
async getProviders(chain) {
|
|
73
90
|
if (chain) {
|
|
74
|
-
const
|
|
75
|
-
if (!
|
|
91
|
+
const interfaceType = this.chainToInterfaces[chain];
|
|
92
|
+
if (!interfaceType || interfaceType.length === 0) {
|
|
76
93
|
throw new Error(`No wallet supports chain: ${chain}`);
|
|
77
94
|
}
|
|
78
|
-
const walletsToQuery =
|
|
95
|
+
const walletsToQuery = interfaceType
|
|
79
96
|
.map((iface) => this.wallets[iface])
|
|
80
97
|
.filter(Boolean);
|
|
81
98
|
const providersArrays = await Promise.all(walletsToQuery.map((wallet) => wallet.getProviders()));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.mjs","sources":["../../../src/__wallet__/mobile/manager.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;MAYa,mBAAmB,CAAA;AAmB9B
|
|
1
|
+
{"version":3,"file":"manager.mjs","sources":["../../../src/__wallet__/mobile/manager.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;MAYa,mBAAmB,CAAA;AAmB9B;;;;;;;;;AASG;AACH,IAAA,WAAA,CAAY,GAAyB,EAAA;;QA3B7B,IAAY,CAAA,YAAA,GAA+B,EAAE;;QAM5C,IAAO,CAAA,OAAA,GAA0D,EAAE;;QAGpE,IAAiB,CAAA,iBAAA,GAAkD,EAAE;AAsH7E;;;;;AAKG;AACK,QAAA,IAAA,CAAA,iBAAiB,GAAG,CAC1B,KAAY,EACZ,aAAkC,KAChC;AACF,YAAA,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC;AAAE,gBAAA,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,GAAG,EAAE;YACtE,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAE,CAAC,IAAI,CAAC,aAAa,CAAC;AACpD,SAAC;QA/GC,MAAM,kBAAkB,GACtB,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,uB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
export declare class CrossPlatformWalletStamper implements TStamper {
|
|
3
3
|
private readonly ctx;
|
|
4
4
|
private activeInterfaceType?;
|
|
5
|
+
/**
|
|
6
|
+
* Constructs a CrossPlatformWalletStamper.
|
|
7
|
+
*
|
|
8
|
+
* - Validates that at least one wallet interface is provided.
|
|
9
|
+
* - For each wallet interface, creates an internal `WalletStamper` bound to it.
|
|
10
|
+
* - Ensures the stamper instance is always initialized in a usable state.
|
|
11
|
+
*
|
|
12
|
+
* @param wallets - A partial mapping of wallet interfaces by type.
|
|
13
|
+
* @throws {Error} If no wallet interfaces are provided.
|
|
14
|
+
*/
|
|
5
15
|
constructor(wallets: Partial<Record<WalletInterfaceType, WalletInterface>>);
|
|
6
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Stamps a payload using the specified wallet interface and provider.
|
|
18
|
+
*
|
|
19
|
+
* - Uses the explicitly provided interface and provider if given.
|
|
20
|
+
* - Falls back to the default interface and stored provider otherwise.
|
|
21
|
+
*
|
|
22
|
+
* @param payload - The string payload to sign.
|
|
23
|
+
* @param interfaceType - Optional wallet interface type (defaults to the active or first available).
|
|
24
|
+
* @param provider - Optional provider (defaults to the one set via `setProvider`).
|
|
25
|
+
* @returns A `TStamp` object containing the stamp header name and encoded value.
|
|
26
|
+
* @throws {Error} If no provider is available for the selected interface.
|
|
27
|
+
*/
|
|
7
28
|
stamp(payload: string, interfaceType?: WalletInterfaceType, provider?: WalletProvider): Promise<TStamp>;
|
|
29
|
+
/**
|
|
30
|
+
* Retrieves the public key for the given provider.
|
|
31
|
+
*
|
|
32
|
+
* @param interfaceType - Optional wallet interface type (defaults to the active or first available).
|
|
33
|
+
* @param provider - Wallet provider for which to fetch the public key.
|
|
34
|
+
* @returns A promise resolving to the public key in hex format.
|
|
35
|
+
*/
|
|
8
36
|
getPublicKey(interfaceType: WalletInterfaceType | undefined, provider: WalletProvider): Promise<string>;
|
|
37
|
+
/**
|
|
38
|
+
* Sets the active provider for a given wallet interface.
|
|
39
|
+
*
|
|
40
|
+
* - The active provider is used as a fallback in `stamp` if none is passed explicitly.
|
|
41
|
+
*
|
|
42
|
+
* @param interfaceType - Wallet interface type.
|
|
43
|
+
* @param provider - Provider instance to associate with the interface.
|
|
44
|
+
*/
|
|
9
45
|
setProvider(interfaceType: WalletInterfaceType, provider: WalletProvider): void;
|
|
10
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Determines the default wallet interface to use when none is specified.
|
|
48
|
+
*
|
|
49
|
+
* - Preference order: Active provider > Ethereum > Solana > WalletConnect.
|
|
50
|
+
*
|
|
51
|
+
* @returns The default wallet interface type.
|
|
52
|
+
* @throws {Error} If no wallet interfaces are initialized.
|
|
53
|
+
*/
|
|
11
54
|
private defaultInterface;
|
|
55
|
+
/**
|
|
56
|
+
* Retrieves the internal context for a given wallet interface.
|
|
57
|
+
*
|
|
58
|
+
* @param interfaceType - Wallet interface type.
|
|
59
|
+
* @returns The context including wallet, stamper, and optional provider.
|
|
60
|
+
* @throws {Error} If the interface is not initialized.
|
|
61
|
+
*/
|
|
12
62
|
private getCtx;
|
|
13
63
|
}
|
|
14
64
|
export declare class WalletStamper {
|
|
15
65
|
private readonly wallet;
|
|
66
|
+
/**
|
|
67
|
+
* Constructs a WalletStamper bound to a single wallet interface.
|
|
68
|
+
*
|
|
69
|
+
* @param wallet - The wallet interface used for signing.
|
|
70
|
+
*/
|
|
16
71
|
constructor(wallet: WalletInterface);
|
|
72
|
+
/**
|
|
73
|
+
* Signs a payload and returns a standardized stamp header.
|
|
74
|
+
*
|
|
75
|
+
* - For Ethereum:
|
|
76
|
+
* - Signs using EIP-191.
|
|
77
|
+
* - Recovers and compresses the public key.
|
|
78
|
+
* - Converts the signature into DER format.
|
|
79
|
+
* - For Solana:
|
|
80
|
+
* - Signs using Ed25519.
|
|
81
|
+
* - Fetches the public key directly from the wallet.
|
|
82
|
+
*
|
|
83
|
+
* @param payload - The payload to sign.
|
|
84
|
+
* @param provider - The wallet provider used for signing.
|
|
85
|
+
* @returns A `TStamp` containing the header name and base64url-encoded JSON value.
|
|
86
|
+
* @throws {Error} If signing or public key recovery fails.
|
|
87
|
+
*/
|
|
17
88
|
stamp(payload: string, provider: WalletProvider): Promise<TStamp>;
|
|
18
89
|
}
|
|
19
90
|
//# sourceMappingURL=stamper.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stamper.d.ts","sourceRoot":"","sources":["../../src/__wallet__/stamper.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,MAAM,EACX,KAAK,QAAQ,EACb,KAAK,cAAc,EACnB,mBAAmB,EACpB,MAAM,QAAQ,CAAC;AAsBhB,qBAAa,0BAA2B,YAAW,QAAQ;IACzD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAkB;IACtC,OAAO,CAAC,mBAAmB,CAAC,CAAsB;
|
|
1
|
+
{"version":3,"file":"stamper.d.ts","sourceRoot":"","sources":["../../src/__wallet__/stamper.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,MAAM,EACX,KAAK,QAAQ,EACb,KAAK,cAAc,EACnB,mBAAmB,EACpB,MAAM,QAAQ,CAAC;AAsBhB,qBAAa,0BAA2B,YAAW,QAAQ;IACzD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAkB;IACtC,OAAO,CAAC,mBAAmB,CAAC,CAAsB;IAElD;;;;;;;;;OASG;gBACS,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,mBAAmB,EAAE,eAAe,CAAC,CAAC;IAiB1E;;;;;;;;;;;OAWG;IACG,KAAK,CACT,OAAO,EAAE,MAAM,EACf,aAAa,GAAE,mBAA6C,EAC5D,QAAQ,CAAC,EAAE,cAAc,GACxB,OAAO,CAAC,MAAM,CAAC;IAalB;;;;;;OAMG;IACG,YAAY,CAChB,aAAa,iCAA+C,EAC5D,QAAQ,EAAE,cAAc,GACvB,OAAO,CAAC,MAAM,CAAC;IAIlB;;;;;;;OAOG;IACH,WAAW,CACT,aAAa,EAAE,mBAAmB,EAClC,QAAQ,EAAE,cAAc,GACvB,IAAI;IAKP;;;;;;;OAOG;IACH,OAAO,CAAC,gBAAgB;IAwBxB;;;;;;OAMG;IACH,OAAO,CAAC,MAAM;CASf;AAED,qBAAa,aAAa;IAMZ,OAAO,CAAC,QAAQ,CAAC,MAAM;IALnC;;;;OAIG;gBAC0B,MAAM,EAAE,eAAe;IAEpD;;;;;;;;;;;;;;;OAeG;IACG,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC;CAqDxE"}
|
|
@@ -8,21 +8,39 @@ const SIGNATURE_SCHEME_TK_API_SECP256K1_EIP191 = "SIGNATURE_SCHEME_TK_API_SECP25
|
|
|
8
8
|
const SIGNATURE_SCHEME_TK_API_ED25519 = "SIGNATURE_SCHEME_TK_API_ED25519";
|
|
9
9
|
const STAMP_HEADER_NAME = "X-Stamp";
|
|
10
10
|
class CrossPlatformWalletStamper {
|
|
11
|
+
/**
|
|
12
|
+
* Constructs a CrossPlatformWalletStamper.
|
|
13
|
+
*
|
|
14
|
+
* - Validates that at least one wallet interface is provided.
|
|
15
|
+
* - For each wallet interface, creates an internal `WalletStamper` bound to it.
|
|
16
|
+
* - Ensures the stamper instance is always initialized in a usable state.
|
|
17
|
+
*
|
|
18
|
+
* @param wallets - A partial mapping of wallet interfaces by type.
|
|
19
|
+
* @throws {Error} If no wallet interfaces are provided.
|
|
20
|
+
*/
|
|
11
21
|
constructor(wallets) {
|
|
12
22
|
this.ctx = {};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
wallet,
|
|
17
|
-
stamper: new WalletStamper(wallet),
|
|
18
|
-
};
|
|
23
|
+
const walletEntries = Object.entries(wallets).filter(([, w]) => Boolean(w));
|
|
24
|
+
if (walletEntries.length === 0) {
|
|
25
|
+
throw new Error("Cannot create WalletStamper: no wallet interfaces provided");
|
|
19
26
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
throw new Error("No interfaces initialized in WalletStamper");
|
|
27
|
+
for (const [interfaceType, wallet] of walletEntries) {
|
|
28
|
+
const typed = interfaceType;
|
|
29
|
+
this.ctx[typed] = { wallet, stamper: new WalletStamper(wallet) };
|
|
24
30
|
}
|
|
25
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Stamps a payload using the specified wallet interface and provider.
|
|
34
|
+
*
|
|
35
|
+
* - Uses the explicitly provided interface and provider if given.
|
|
36
|
+
* - Falls back to the default interface and stored provider otherwise.
|
|
37
|
+
*
|
|
38
|
+
* @param payload - The string payload to sign.
|
|
39
|
+
* @param interfaceType - Optional wallet interface type (defaults to the active or first available).
|
|
40
|
+
* @param provider - Optional provider (defaults to the one set via `setProvider`).
|
|
41
|
+
* @returns A `TStamp` object containing the stamp header name and encoded value.
|
|
42
|
+
* @throws {Error} If no provider is available for the selected interface.
|
|
43
|
+
*/
|
|
26
44
|
async stamp(payload, interfaceType = this.defaultInterface(), provider) {
|
|
27
45
|
const ctx = this.getCtx(interfaceType);
|
|
28
46
|
const selectedProvider = provider ?? ctx.provider;
|
|
@@ -31,16 +49,36 @@ class CrossPlatformWalletStamper {
|
|
|
31
49
|
}
|
|
32
50
|
return ctx.stamper.stamp(payload, selectedProvider);
|
|
33
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Retrieves the public key for the given provider.
|
|
54
|
+
*
|
|
55
|
+
* @param interfaceType - Optional wallet interface type (defaults to the active or first available).
|
|
56
|
+
* @param provider - Wallet provider for which to fetch the public key.
|
|
57
|
+
* @returns A promise resolving to the public key in hex format.
|
|
58
|
+
*/
|
|
34
59
|
async getPublicKey(interfaceType = this.defaultInterface(), provider) {
|
|
35
60
|
return this.getCtx(interfaceType).wallet.getPublicKey(provider);
|
|
36
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Sets the active provider for a given wallet interface.
|
|
64
|
+
*
|
|
65
|
+
* - The active provider is used as a fallback in `stamp` if none is passed explicitly.
|
|
66
|
+
*
|
|
67
|
+
* @param interfaceType - Wallet interface type.
|
|
68
|
+
* @param provider - Provider instance to associate with the interface.
|
|
69
|
+
*/
|
|
37
70
|
setProvider(interfaceType, provider) {
|
|
38
71
|
this.getCtx(interfaceType).provider = provider;
|
|
39
72
|
this.activeInterfaceType = interfaceType;
|
|
40
73
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Determines the default wallet interface to use when none is specified.
|
|
76
|
+
*
|
|
77
|
+
* - Preference order: Active provider > Ethereum > Solana > WalletConnect.
|
|
78
|
+
*
|
|
79
|
+
* @returns The default wallet interface type.
|
|
80
|
+
* @throws {Error} If no wallet interfaces are initialized.
|
|
81
|
+
*/
|
|
44
82
|
defaultInterface() {
|
|
45
83
|
if (this.activeInterfaceType) {
|
|
46
84
|
return this.activeInterfaceType;
|
|
@@ -57,6 +95,13 @@ class CrossPlatformWalletStamper {
|
|
|
57
95
|
}
|
|
58
96
|
throw new Error("No interfaces initialized");
|
|
59
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Retrieves the internal context for a given wallet interface.
|
|
100
|
+
*
|
|
101
|
+
* @param interfaceType - Wallet interface type.
|
|
102
|
+
* @returns The context including wallet, stamper, and optional provider.
|
|
103
|
+
* @throws {Error} If the interface is not initialized.
|
|
104
|
+
*/
|
|
60
105
|
getCtx(interfaceType) {
|
|
61
106
|
const ctx = this.ctx[interfaceType];
|
|
62
107
|
if (!ctx) {
|
|
@@ -66,9 +111,30 @@ class CrossPlatformWalletStamper {
|
|
|
66
111
|
}
|
|
67
112
|
}
|
|
68
113
|
class WalletStamper {
|
|
114
|
+
/**
|
|
115
|
+
* Constructs a WalletStamper bound to a single wallet interface.
|
|
116
|
+
*
|
|
117
|
+
* @param wallet - The wallet interface used for signing.
|
|
118
|
+
*/
|
|
69
119
|
constructor(wallet) {
|
|
70
120
|
this.wallet = wallet;
|
|
71
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* Signs a payload and returns a standardized stamp header.
|
|
124
|
+
*
|
|
125
|
+
* - For Ethereum:
|
|
126
|
+
* - Signs using EIP-191.
|
|
127
|
+
* - Recovers and compresses the public key.
|
|
128
|
+
* - Converts the signature into DER format.
|
|
129
|
+
* - For Solana:
|
|
130
|
+
* - Signs using Ed25519.
|
|
131
|
+
* - Fetches the public key directly from the wallet.
|
|
132
|
+
*
|
|
133
|
+
* @param payload - The payload to sign.
|
|
134
|
+
* @param provider - The wallet provider used for signing.
|
|
135
|
+
* @returns A `TStamp` containing the header name and base64url-encoded JSON value.
|
|
136
|
+
* @throws {Error} If signing or public key recovery fails.
|
|
137
|
+
*/
|
|
72
138
|
async stamp(payload, provider) {
|
|
73
139
|
let signature;
|
|
74
140
|
let publicKey;
|
|
@@ -78,11 +144,11 @@ class WalletStamper {
|
|
|
78
144
|
catch (error) {
|
|
79
145
|
throw new Error(`Failed to sign the message: ${error}`);
|
|
80
146
|
}
|
|
81
|
-
const scheme = utils.
|
|
147
|
+
const scheme = utils.isSolanaProvider(provider)
|
|
82
148
|
? SIGNATURE_SCHEME_TK_API_ED25519
|
|
83
149
|
: SIGNATURE_SCHEME_TK_API_SECP256K1_EIP191;
|
|
84
150
|
try {
|
|
85
|
-
if (utils.
|
|
151
|
+
if (utils.isEthereumProvider(provider)) {
|
|
86
152
|
const { recoverPublicKey, hashMessage } = await import('viem');
|
|
87
153
|
const { compressRawPublicKey, toDerSignature } = await import('@turnkey/crypto');
|
|
88
154
|
const rawPublicKey = await recoverPublicKey({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stamper.js","sources":["../../src/__wallet__/stamper.ts"],"sourcesContent":[null],"names":["WalletInterfaceType","SignIntent","
|
|
1
|
+
{"version":3,"file":"stamper.js","sources":["../../src/__wallet__/stamper.ts"],"sourcesContent":[null],"names":["WalletInterfaceType","SignIntent","isSolanaProvider","isEthereumProvider","uint8ArrayFromHexString","uint8Array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AS,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,QAAQ,CAAC;;;QAEtD,OAAO,KAAK,EAAE;AACd,YAAA,MAAM,IAAI,KAAK,CAAC,iCAAiC,KAAK,CAAA,CAAE,CAAC;;QAG3D,OAAO;AACL,YAAA,eAAe,EAAE,iBAAiB;AAClC,YAAA,gBAAgB,EAAEC,gCAAuB,CACvC,IAAI,CAAC,SAAS,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CACjD;SACF;;AAEJ;;;;;"}
|
|
@@ -1,26 +1,44 @@
|
|
|
1
1
|
import { WalletInterfaceType, SignIntent } from '../__types__/base.mjs';
|
|
2
2
|
import { uint8ArrayFromHexString, uint8ArrayToHexString, stringToBase64urlString } from '@turnkey/encoding';
|
|
3
|
-
import {
|
|
3
|
+
import { isSolanaProvider, isEthereumProvider } from '../utils.mjs';
|
|
4
4
|
|
|
5
5
|
const SIGNATURE_SCHEME_TK_API_SECP256K1_EIP191 = "SIGNATURE_SCHEME_TK_API_SECP256K1_EIP191";
|
|
6
6
|
const SIGNATURE_SCHEME_TK_API_ED25519 = "SIGNATURE_SCHEME_TK_API_ED25519";
|
|
7
7
|
const STAMP_HEADER_NAME = "X-Stamp";
|
|
8
8
|
class CrossPlatformWalletStamper {
|
|
9
|
+
/**
|
|
10
|
+
* Constructs a CrossPlatformWalletStamper.
|
|
11
|
+
*
|
|
12
|
+
* - Validates that at least one wallet interface is provided.
|
|
13
|
+
* - For each wallet interface, creates an internal `WalletStamper` bound to it.
|
|
14
|
+
* - Ensures the stamper instance is always initialized in a usable state.
|
|
15
|
+
*
|
|
16
|
+
* @param wallets - A partial mapping of wallet interfaces by type.
|
|
17
|
+
* @throws {Error} If no wallet interfaces are provided.
|
|
18
|
+
*/
|
|
9
19
|
constructor(wallets) {
|
|
10
20
|
this.ctx = {};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
wallet,
|
|
15
|
-
stamper: new WalletStamper(wallet),
|
|
16
|
-
};
|
|
21
|
+
const walletEntries = Object.entries(wallets).filter(([, w]) => Boolean(w));
|
|
22
|
+
if (walletEntries.length === 0) {
|
|
23
|
+
throw new Error("Cannot create WalletStamper: no wallet interfaces provided");
|
|
17
24
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
throw new Error("No interfaces initialized in WalletStamper");
|
|
25
|
+
for (const [interfaceType, wallet] of walletEntries) {
|
|
26
|
+
const typed = interfaceType;
|
|
27
|
+
this.ctx[typed] = { wallet, stamper: new WalletStamper(wallet) };
|
|
22
28
|
}
|
|
23
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Stamps a payload using the specified wallet interface and provider.
|
|
32
|
+
*
|
|
33
|
+
* - Uses the explicitly provided interface and provider if given.
|
|
34
|
+
* - Falls back to the default interface and stored provider otherwise.
|
|
35
|
+
*
|
|
36
|
+
* @param payload - The string payload to sign.
|
|
37
|
+
* @param interfaceType - Optional wallet interface type (defaults to the active or first available).
|
|
38
|
+
* @param provider - Optional provider (defaults to the one set via `setProvider`).
|
|
39
|
+
* @returns A `TStamp` object containing the stamp header name and encoded value.
|
|
40
|
+
* @throws {Error} If no provider is available for the selected interface.
|
|
41
|
+
*/
|
|
24
42
|
async stamp(payload, interfaceType = this.defaultInterface(), provider) {
|
|
25
43
|
const ctx = this.getCtx(interfaceType);
|
|
26
44
|
const selectedProvider = provider ?? ctx.provider;
|
|
@@ -29,16 +47,36 @@ class CrossPlatformWalletStamper {
|
|
|
29
47
|
}
|
|
30
48
|
return ctx.stamper.stamp(payload, selectedProvider);
|
|
31
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Retrieves the public key for the given provider.
|
|
52
|
+
*
|
|
53
|
+
* @param interfaceType - Optional wallet interface type (defaults to the active or first available).
|
|
54
|
+
* @param provider - Wallet provider for which to fetch the public key.
|
|
55
|
+
* @returns A promise resolving to the public key in hex format.
|
|
56
|
+
*/
|
|
32
57
|
async getPublicKey(interfaceType = this.defaultInterface(), provider) {
|
|
33
58
|
return this.getCtx(interfaceType).wallet.getPublicKey(provider);
|
|
34
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Sets the active provider for a given wallet interface.
|
|
62
|
+
*
|
|
63
|
+
* - The active provider is used as a fallback in `stamp` if none is passed explicitly.
|
|
64
|
+
*
|
|
65
|
+
* @param interfaceType - Wallet interface type.
|
|
66
|
+
* @param provider - Provider instance to associate with the interface.
|
|
67
|
+
*/
|
|
35
68
|
setProvider(interfaceType, provider) {
|
|
36
69
|
this.getCtx(interfaceType).provider = provider;
|
|
37
70
|
this.activeInterfaceType = interfaceType;
|
|
38
71
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
72
|
+
/**
|
|
73
|
+
* Determines the default wallet interface to use when none is specified.
|
|
74
|
+
*
|
|
75
|
+
* - Preference order: Active provider > Ethereum > Solana > WalletConnect.
|
|
76
|
+
*
|
|
77
|
+
* @returns The default wallet interface type.
|
|
78
|
+
* @throws {Error} If no wallet interfaces are initialized.
|
|
79
|
+
*/
|
|
42
80
|
defaultInterface() {
|
|
43
81
|
if (this.activeInterfaceType) {
|
|
44
82
|
return this.activeInterfaceType;
|
|
@@ -55,6 +93,13 @@ class CrossPlatformWalletStamper {
|
|
|
55
93
|
}
|
|
56
94
|
throw new Error("No interfaces initialized");
|
|
57
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Retrieves the internal context for a given wallet interface.
|
|
98
|
+
*
|
|
99
|
+
* @param interfaceType - Wallet interface type.
|
|
100
|
+
* @returns The context including wallet, stamper, and optional provider.
|
|
101
|
+
* @throws {Error} If the interface is not initialized.
|
|
102
|
+
*/
|
|
58
103
|
getCtx(interfaceType) {
|
|
59
104
|
const ctx = this.ctx[interfaceType];
|
|
60
105
|
if (!ctx) {
|
|
@@ -64,9 +109,30 @@ class CrossPlatformWalletStamper {
|
|
|
64
109
|
}
|
|
65
110
|
}
|
|
66
111
|
class WalletStamper {
|
|
112
|
+
/**
|
|
113
|
+
* Constructs a WalletStamper bound to a single wallet interface.
|
|
114
|
+
*
|
|
115
|
+
* @param wallet - The wallet interface used for signing.
|
|
116
|
+
*/
|
|
67
117
|
constructor(wallet) {
|
|
68
118
|
this.wallet = wallet;
|
|
69
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Signs a payload and returns a standardized stamp header.
|
|
122
|
+
*
|
|
123
|
+
* - For Ethereum:
|
|
124
|
+
* - Signs using EIP-191.
|
|
125
|
+
* - Recovers and compresses the public key.
|
|
126
|
+
* - Converts the signature into DER format.
|
|
127
|
+
* - For Solana:
|
|
128
|
+
* - Signs using Ed25519.
|
|
129
|
+
* - Fetches the public key directly from the wallet.
|
|
130
|
+
*
|
|
131
|
+
* @param payload - The payload to sign.
|
|
132
|
+
* @param provider - The wallet provider used for signing.
|
|
133
|
+
* @returns A `TStamp` containing the header name and base64url-encoded JSON value.
|
|
134
|
+
* @throws {Error} If signing or public key recovery fails.
|
|
135
|
+
*/
|
|
70
136
|
async stamp(payload, provider) {
|
|
71
137
|
let signature;
|
|
72
138
|
let publicKey;
|
|
@@ -76,11 +142,11 @@ class WalletStamper {
|
|
|
76
142
|
catch (error) {
|
|
77
143
|
throw new Error(`Failed to sign the message: ${error}`);
|
|
78
144
|
}
|
|
79
|
-
const scheme =
|
|
145
|
+
const scheme = isSolanaProvider(provider)
|
|
80
146
|
? SIGNATURE_SCHEME_TK_API_ED25519
|
|
81
147
|
: SIGNATURE_SCHEME_TK_API_SECP256K1_EIP191;
|
|
82
148
|
try {
|
|
83
|
-
if (
|
|
149
|
+
if (isEthereumProvider(provider)) {
|
|
84
150
|
const { recoverPublicKey, hashMessage } = await import('viem');
|
|
85
151
|
const { compressRawPublicKey, toDerSignature } = await import('@turnkey/crypto');
|
|
86
152
|
const rawPublicKey = await recoverPublicKey({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stamper.mjs","sources":["../../src/__wallet__/stamper.ts"],"sourcesContent":[null],"names":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