@zerodev/wallet-core 0.0.1-alpha.4 → 0.0.1-alpha.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zerodev/wallet-core",
3
- "version": "0.0.1-alpha.4",
3
+ "version": "0.0.1-alpha.5",
4
4
  "description": "ZeroDev Wallet SDK built on Turnkey",
5
5
  "main": "./dist/_cjs/index.js",
6
6
  "module": "./dist/_esm/index.js",
@@ -6,11 +6,13 @@ export type GetUserWalletParameters = {
6
6
  organizationId: string
7
7
  /** The project ID for the request */
8
8
  projectId: string
9
+ /** The token for the request */
10
+ token: string
9
11
  }
10
12
 
11
13
  export type GetUserWalletReturnType = {
12
14
  /** The wallet address */
13
- walletAddress: Hex
15
+ walletAddresses: Hex[]
14
16
  /** The user ID */
15
17
  userId?: string
16
18
  }
@@ -28,19 +30,24 @@ export type GetUserWalletReturnType = {
28
30
  * organizationId: 'org_123',
29
31
  * projectId: 'proj_456'
30
32
  * });
31
- * console.log(wallet.walletAddress); // '0x...'
33
+ * console.log(wallet.walletAddresses); // ['0x...', '0x...']
32
34
  * ```
33
35
  */
34
36
  export async function getUserWallet(
35
37
  client: Client,
36
38
  params: GetUserWalletParameters,
37
39
  ): Promise<GetUserWalletReturnType> {
38
- const { organizationId, projectId } = params
40
+ const { organizationId, projectId, token } = params
39
41
 
40
42
  return await client.request({
41
43
  path: `${projectId}/user-wallet`,
42
44
  body: {
43
45
  organizationId,
44
46
  },
47
+ headers: {
48
+ Authorization: `Bearer ${token}`,
49
+ },
50
+ stamp: true,
51
+ stampPostion: 'headers',
45
52
  })
46
53
  }
@@ -24,12 +24,13 @@ export interface ToViemAccountParams {
24
24
  client: ZeroDevWalletClient
25
25
  organizationId: string
26
26
  projectId: string
27
+ token: string
27
28
  }
28
29
 
29
30
  export async function toViemAccount(
30
31
  params: ToViemAccountParams,
31
32
  ): Promise<LocalAccount> {
32
- const { client, organizationId, projectId } = params
33
+ const { client, organizationId, projectId, token } = params
33
34
 
34
35
  let address: Hex = zeroAddress
35
36
 
@@ -37,8 +38,9 @@ export async function toViemAccount(
37
38
  const walletResponse = await client.getUserWallet({
38
39
  organizationId,
39
40
  projectId,
41
+ token,
40
42
  })
41
- address = walletResponse.walletAddress
43
+ address = walletResponse.walletAddresses[0]
42
44
  } catch {
43
45
  address = zeroAddress
44
46
  }
@@ -8,6 +8,7 @@ export type RestRequestArgs = {
8
8
  headers?: Record<string, string>
9
9
  stamp?: boolean
10
10
  stampWith?: 'indexedDb' | 'webAuthn'
11
+ stampPostion?: 'body' | 'headers'
11
12
  }
12
13
 
13
14
  export type RestRequestFn = <T = any>(args: RestRequestArgs) => Promise<T>
@@ -44,7 +45,7 @@ export function rest(url: string, cfg: RestTransportConfig): RestTransport {
44
45
 
45
46
  try {
46
47
  let requestBody = args.body
47
- const requestHeaders = {
48
+ let requestHeaders = {
48
49
  'content-type': 'application/json',
49
50
  ...(args.headers ?? {}),
50
51
  ...(cfg.fetchOptions?.headers ?? {}),
@@ -65,7 +66,12 @@ export function rest(url: string, cfg: RestTransportConfig): RestTransport {
65
66
  const stamp = await stamper.stamp(bodyString)
66
67
 
67
68
  // Restructure request body to match backend expectation
68
- if (body) {
69
+ if (args.stampPostion === 'headers') {
70
+ requestHeaders = {
71
+ ...requestHeaders,
72
+ [stamp.stampHeaderName]: stamp.stampHeaderValue,
73
+ }
74
+ } else if (body) {
69
75
  requestBody = {
70
76
  body: bodyString,
71
77
  stamp: {
@@ -422,6 +422,7 @@ export async function createZeroDevWallet(
422
422
  client,
423
423
  organizationId: session.organizationId,
424
424
  projectId,
425
+ token: session.token ?? '',
425
426
  })
426
427
  },
427
428
  }