@zerodev/wallet-core 0.0.1 → 0.0.3

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/package.json CHANGED
@@ -1,7 +1,12 @@
1
1
  {
2
2
  "name": "@zerodev/wallet-core",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "ZeroDev Wallet SDK built on Turnkey",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/zerodevapp/zerodev-wallet-sdk.git",
8
+ "directory": "packages/core"
9
+ },
5
10
  "sideEffects": false,
6
11
  "main": "./dist/_cjs/index.js",
7
12
  "module": "./dist/_esm/index.js",
@@ -108,7 +113,7 @@
108
113
  "json-canonicalize": "^2.0.0"
109
114
  },
110
115
  "peerDependencies": {
111
- "viem": "^2.38.0",
116
+ "viem": "^2.47.18",
112
117
  "@react-native-async-storage/async-storage": ">=2.0.0",
113
118
  "@turnkey/api-key-stamper": ">=0.6.0",
114
119
  "@turnkey/crypto": ">=2.8.0",
@@ -149,7 +154,7 @@
149
154
  "@types/node": "^20.0.0",
150
155
  "expo-secure-store": "55.0.9",
151
156
  "typescript": "5.9.3",
152
- "uuid": "^13.0.0"
157
+ "uuid": "^13.0.2"
153
158
  },
154
159
  "scripts": {
155
160
  "build": "pnpm run clean && pnpm run build:cjs && pnpm run build:esm && pnpm run build:types",
@@ -4,6 +4,8 @@ import {
4
4
  getTypesForEIP712Domain,
5
5
  type Hex,
6
6
  hashTypedData,
7
+ isAddress,
8
+ isAddressEqual,
7
9
  type LocalAccount,
8
10
  numberToHex,
9
11
  parseSignature,
@@ -35,17 +37,20 @@ export async function toViemAccount(
35
37
  ): Promise<LocalAccount> {
36
38
  const { client, organizationId, projectId, getToken } = params
37
39
 
38
- let address: Hex = zeroAddress
39
-
40
- try {
41
- const walletResponse = await client.getUserWallet({
42
- organizationId,
43
- projectId,
44
- token: await getToken(),
45
- })
46
- address = walletResponse.walletAddresses[0]
47
- } catch {
48
- address = zeroAddress
40
+ const walletResponse = await client.getUserWallet({
41
+ organizationId,
42
+ projectId,
43
+ token: await getToken(),
44
+ })
45
+ const address = walletResponse.walletAddresses[0]
46
+ if (
47
+ !address ||
48
+ !isAddress(address, { strict: false }) ||
49
+ isAddressEqual(address, zeroAddress)
50
+ ) {
51
+ throw new Error(
52
+ `Cannot build account: wallet address is missing, malformed, or zero for organization ${organizationId} (got ${address ?? 'undefined'}).`,
53
+ )
49
54
  }
50
55
 
51
56
  // Modified from: https://github.com/tkhq/sdk/blob/4e439bf2973ea13b51d981d7c24a4841d4e5fd5f/packages/viem/src/index.ts#L419-L461
@@ -459,7 +459,12 @@ export async function createZeroDevWalletCore(
459
459
  projectId,
460
460
  getToken: async () => {
461
461
  const activeSession = await sessionStorageManager.getActiveSession()
462
- return activeSession?.token ?? ''
462
+ if (!activeSession?.token) {
463
+ throw new Error(
464
+ 'No active session token; refusing to build an account without authentication.',
465
+ )
466
+ }
467
+ return activeSession.token
463
468
  },
464
469
  })
465
470
  },
@@ -33,6 +33,13 @@ export async function createWebauthnStamper({
33
33
  name: options.userName,
34
34
  displayName: options.userName,
35
35
  },
36
+ // Login resolves the credential with an empty allowCredentials list,
37
+ // which can only surface discoverable (resident) credentials — so the
38
+ // credential must be created as resident.
39
+ authenticatorSelection: {
40
+ residentKey: 'required',
41
+ userVerification: 'preferred',
42
+ },
36
43
  },
37
44
  })
38
45
 
package/src/utils/hpke.ts CHANGED
@@ -58,9 +58,10 @@ function concat(...parts: Uint8Array[]): Uint8Array {
58
58
 
59
59
  function i2osp(n: number, len: number): Uint8Array {
60
60
  const out = new Uint8Array(len)
61
+ let value = n
61
62
  for (let i = len - 1; i >= 0; i--) {
62
- out[i] = n & 0xff
63
- n >>>= 8
63
+ out[i] = value & 0xff
64
+ value >>>= 8
64
65
  }
65
66
  return out
66
67
  }