@crossmint/client-sdk-smart-wallet 0.1.12 → 0.1.13
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/index.cjs +3 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/package.json +4 -5
- package/src/SmartWalletSDK.ts +31 -7
- package/src/api/CrossmintWalletService.test.ts +1 -1
- package/src/blockchain/chains.ts +8 -0
- package/src/index.ts +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crossmint/client-sdk-smart-wallet",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.13",
|
|
4
4
|
"repository": "https://github.com/Crossmint/crossmint-sdk",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Paella Labs Inc",
|
|
@@ -26,14 +26,13 @@
|
|
|
26
26
|
"permissionless": "0.1.36",
|
|
27
27
|
"viem": "2.17.5",
|
|
28
28
|
"zod": "3.22.4",
|
|
29
|
-
"@crossmint/client-sdk-base": "1.2.
|
|
30
|
-
"@crossmint/common-sdk-base": "0.1.
|
|
29
|
+
"@crossmint/client-sdk-base": "1.2.6",
|
|
30
|
+
"@crossmint/common-sdk-base": "0.1.4"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"typedoc": "0.26.5",
|
|
34
34
|
"typedoc-plugin-frontmatter": "1.0.0",
|
|
35
|
-
"typedoc-plugin-markdown": "4.2.3"
|
|
36
|
-
"vitest-mock-extended": "2.0.0"
|
|
35
|
+
"typedoc-plugin-markdown": "4.2.3"
|
|
37
36
|
},
|
|
38
37
|
"scripts": {
|
|
39
38
|
"build": "tsup src/index.ts --clean --format esm,cjs --outDir ./dist --minify --dts --sourcemap",
|
package/src/SmartWalletSDK.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { stringify } from "viem";
|
|
2
2
|
|
|
3
|
-
import { validateAPIKey } from "@crossmint/common-sdk-base";
|
|
3
|
+
import { APIKeyEnvironmentPrefix, validateAPIKey } from "@crossmint/common-sdk-base";
|
|
4
4
|
|
|
5
5
|
import { CrossmintWalletService } from "./api/CrossmintWalletService";
|
|
6
|
-
import
|
|
6
|
+
import {
|
|
7
|
+
SMART_WALLET_MAINNETS,
|
|
8
|
+
SMART_WALLET_TESTNETS,
|
|
9
|
+
type SmartWalletChain,
|
|
10
|
+
isMainnetChain,
|
|
11
|
+
isTestnetChain,
|
|
12
|
+
} from "./blockchain/chains";
|
|
7
13
|
import type { EVMSmartWallet } from "./blockchain/wallets";
|
|
8
14
|
import { AccountConfigCache } from "./blockchain/wallets/account/cache";
|
|
9
15
|
import { AccountConfigService } from "./blockchain/wallets/account/config";
|
|
@@ -21,6 +27,7 @@ import { isClient } from "./utils/environment";
|
|
|
21
27
|
|
|
22
28
|
export class SmartWalletSDK {
|
|
23
29
|
private constructor(
|
|
30
|
+
private readonly crossmintEnv: APIKeyEnvironmentPrefix,
|
|
24
31
|
private readonly smartWalletService: SmartWalletService,
|
|
25
32
|
private readonly errorProcessor: ErrorProcessor,
|
|
26
33
|
private readonly logger = scwLogger
|
|
@@ -31,10 +38,6 @@ export class SmartWalletSDK {
|
|
|
31
38
|
* @throws error if the api key is not formatted correctly.
|
|
32
39
|
*/
|
|
33
40
|
static init({ clientApiKey }: SmartWalletSDKInitParams): SmartWalletSDK {
|
|
34
|
-
if (!isClient()) {
|
|
35
|
-
throw new SmartWalletError("Smart Wallet SDK should only be used client side.");
|
|
36
|
-
}
|
|
37
|
-
|
|
38
41
|
const validationResult = validateAPIKey(clientApiKey);
|
|
39
42
|
if (!validationResult.isValid) {
|
|
40
43
|
throw new Error("API key invalid");
|
|
@@ -55,7 +58,7 @@ export class SmartWalletSDK {
|
|
|
55
58
|
new ClientDecorator(errorProcessor)
|
|
56
59
|
);
|
|
57
60
|
|
|
58
|
-
return new SmartWalletSDK(smartWalletService, errorProcessor);
|
|
61
|
+
return new SmartWalletSDK(validationResult.environment, smartWalletService, errorProcessor);
|
|
59
62
|
}
|
|
60
63
|
|
|
61
64
|
/**
|
|
@@ -72,6 +75,11 @@ export class SmartWalletSDK {
|
|
|
72
75
|
chain: SmartWalletChain,
|
|
73
76
|
walletParams: WalletParams = { signer: { type: "PASSKEY" } }
|
|
74
77
|
): Promise<EVMSmartWallet> {
|
|
78
|
+
if (!isClient()) {
|
|
79
|
+
throw new SmartWalletError("Smart Wallet SDK should only be used client side.");
|
|
80
|
+
}
|
|
81
|
+
this.assertValidChain(chain);
|
|
82
|
+
|
|
75
83
|
return this.logger.logPerformance("GET_OR_CREATE_WALLET", async () => {
|
|
76
84
|
try {
|
|
77
85
|
return await this.smartWalletService.getOrCreate(user, chain, walletParams);
|
|
@@ -83,4 +91,20 @@ export class SmartWalletSDK {
|
|
|
83
91
|
}
|
|
84
92
|
});
|
|
85
93
|
}
|
|
94
|
+
|
|
95
|
+
private assertValidChain(chain: SmartWalletChain) {
|
|
96
|
+
if (!this.validChain(chain)) {
|
|
97
|
+
throw new SmartWalletError(
|
|
98
|
+
`The selected chain "${chain}" is not available in "${this.crossmintEnv}". Either set a valid chain or check you're using an API key for the environment you're trying to target.`
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private validChain(chain: SmartWalletChain): boolean {
|
|
104
|
+
if (this.crossmintEnv === "development" || this.crossmintEnv === "staging") {
|
|
105
|
+
return isTestnetChain(chain);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return isMainnetChain(chain);
|
|
109
|
+
}
|
|
86
110
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
2
|
|
|
3
|
-
import { CROSSMINT_STG_URL } from "@crossmint/
|
|
3
|
+
import { CROSSMINT_STG_URL } from "@crossmint/common-sdk-base";
|
|
4
4
|
|
|
5
5
|
import { CrossmintWalletService } from "./CrossmintWalletService";
|
|
6
6
|
|
package/src/blockchain/chains.ts
CHANGED
|
@@ -37,6 +37,14 @@ export const SmartWalletChain = {
|
|
|
37
37
|
export type SmartWalletChain = ObjectValues<typeof SmartWalletChain>;
|
|
38
38
|
export const SMART_WALLET_CHAINS = objectValues(SmartWalletChain);
|
|
39
39
|
|
|
40
|
+
export function isTestnetChain(chain: SmartWalletChain): chain is SmartWalletTestnet {
|
|
41
|
+
return (SMART_WALLET_TESTNETS as any).includes(chain);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function isMainnetChain(chain: SmartWalletChain): chain is SmartWalletMainnet {
|
|
45
|
+
return (SMART_WALLET_MAINNETS as any).includes(chain);
|
|
46
|
+
}
|
|
47
|
+
|
|
40
48
|
export const viemNetworks: Record<SmartWalletChain, Chain> = {
|
|
41
49
|
polygon: polygon,
|
|
42
50
|
"polygon-amoy": polygonAmoy,
|
package/src/index.ts
CHANGED
|
@@ -11,6 +11,8 @@ export type {
|
|
|
11
11
|
WalletParams,
|
|
12
12
|
} from "./types/params";
|
|
13
13
|
|
|
14
|
+
export type { SmartWalletChain as EVMSmartWalletChain } from "./blockchain/chains";
|
|
15
|
+
|
|
14
16
|
export type { TransferType, ERC20TransferType, NFTTransferType, SFTTransferType } from "./types/token";
|
|
15
17
|
|
|
16
18
|
export {
|