@privy-io/node 0.1.0-alpha.2 → 0.1.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/CHANGELOG.md +40 -0
- package/client.d.mts +3 -3
- package/client.d.mts.map +1 -1
- package/client.d.ts +3 -3
- package/client.d.ts.map +1 -1
- package/client.js +1 -1
- package/client.js.map +1 -1
- package/client.mjs +1 -1
- package/client.mjs.map +1 -1
- package/index.d.mts +6 -0
- package/index.d.mts.map +1 -1
- package/index.d.ts +6 -0
- package/index.d.ts.map +1 -1
- package/index.js +7 -1
- package/index.js.map +1 -1
- package/index.mjs +2 -0
- package/index.mjs.map +1 -1
- package/internal/utils/values.js +3 -3
- package/internal/utils/values.js.map +1 -1
- package/internal/utils/values.mjs +3 -3
- package/internal/utils/values.mjs.map +1 -1
- package/lib/auth.d.mts +68 -0
- package/lib/auth.d.mts.map +1 -0
- package/lib/auth.d.ts +68 -0
- package/lib/auth.d.ts.map +1 -0
- package/lib/auth.js +130 -0
- package/lib/auth.js.map +1 -0
- package/lib/auth.mjs +123 -0
- package/lib/auth.mjs.map +1 -0
- package/lib/identity-token.d.mts +15 -0
- package/lib/identity-token.d.mts.map +1 -0
- package/lib/identity-token.d.ts +15 -0
- package/lib/identity-token.d.ts.map +1 -0
- package/lib/identity-token.js +273 -0
- package/lib/identity-token.js.map +1 -0
- package/lib/identity-token.mjs +268 -0
- package/lib/identity-token.mjs.map +1 -0
- package/lib/user-utils.d.mts +22 -0
- package/lib/user-utils.d.mts.map +1 -0
- package/lib/user-utils.d.ts +22 -0
- package/lib/user-utils.d.ts.map +1 -0
- package/lib/user-utils.js +15 -0
- package/lib/user-utils.js.map +1 -0
- package/lib/user-utils.mjs +11 -0
- package/lib/user-utils.mjs.map +1 -0
- package/package.json +19 -1
- package/public-api/PrivyClient.d.mts +2 -1
- package/public-api/PrivyClient.d.mts.map +1 -1
- package/public-api/PrivyClient.d.ts +2 -1
- package/public-api/PrivyClient.d.ts.map +1 -1
- package/public-api/PrivyClient.js +10 -3
- package/public-api/PrivyClient.js.map +1 -1
- package/public-api/PrivyClient.mjs +10 -3
- package/public-api/PrivyClient.mjs.map +1 -1
- package/public-api/services/ethereum.d.mts.map +1 -1
- package/public-api/services/ethereum.d.ts.map +1 -1
- package/public-api/services/ethereum.js +0 -6
- package/public-api/services/ethereum.js.map +1 -1
- package/public-api/services/ethereum.mjs +0 -6
- package/public-api/services/ethereum.mjs.map +1 -1
- package/public-api/services/solana.d.mts.map +1 -1
- package/public-api/services/solana.d.ts.map +1 -1
- package/public-api/services/solana.js +0 -3
- package/public-api/services/solana.js.map +1 -1
- package/public-api/services/solana.mjs +0 -3
- package/public-api/services/solana.mjs.map +1 -1
- package/public-api/services/users.d.mts +23 -1
- package/public-api/services/users.d.mts.map +1 -1
- package/public-api/services/users.d.ts +23 -1
- package/public-api/services/users.d.ts.map +1 -1
- package/public-api/services/users.js +24 -0
- package/public-api/services/users.js.map +1 -1
- package/public-api/services/users.mjs +24 -0
- package/public-api/services/users.mjs.map +1 -1
- package/public-api/services/utils/auth.d.mts +18 -0
- package/public-api/services/utils/auth.d.mts.map +1 -0
- package/public-api/services/utils/auth.d.ts +18 -0
- package/public-api/services/utils/auth.d.ts.map +1 -0
- package/public-api/services/utils/auth.js +33 -0
- package/public-api/services/utils/auth.js.map +1 -0
- package/public-api/services/utils/auth.mjs +29 -0
- package/public-api/services/utils/auth.mjs.map +1 -0
- package/public-api/services/utils/request-formatter.d.mts +5 -0
- package/public-api/services/utils/request-formatter.d.mts.map +1 -0
- package/public-api/services/utils/request-formatter.d.ts +5 -0
- package/public-api/services/utils/request-formatter.d.ts.map +1 -0
- package/public-api/services/utils/request-formatter.js +12 -0
- package/public-api/services/utils/request-formatter.js.map +1 -0
- package/public-api/services/utils/request-formatter.mjs +8 -0
- package/public-api/services/utils/request-formatter.mjs.map +1 -0
- package/public-api/services/utils/request-signer.d.mts +25 -0
- package/public-api/services/utils/request-signer.d.mts.map +1 -0
- package/public-api/services/utils/request-signer.d.ts +25 -0
- package/public-api/services/utils/request-signer.d.ts.map +1 -0
- package/public-api/services/utils/request-signer.js +17 -0
- package/public-api/services/utils/request-signer.js.map +1 -0
- package/public-api/services/utils/request-signer.mjs +13 -0
- package/public-api/services/utils/request-signer.mjs.map +1 -0
- package/public-api/services/utils.d.mts +12 -22
- package/public-api/services/utils.d.mts.map +1 -1
- package/public-api/services/utils.d.ts +12 -22
- package/public-api/services/utils.d.ts.map +1 -1
- package/public-api/services/utils.js +15 -9
- package/public-api/services/utils.js.map +1 -1
- package/public-api/services/utils.mjs +16 -10
- package/public-api/services/utils.mjs.map +1 -1
- package/resources/index.d.mts +1 -1
- package/resources/index.d.mts.map +1 -1
- package/resources/index.d.ts +1 -1
- package/resources/index.d.ts.map +1 -1
- package/resources/policies.d.mts +2 -1
- package/resources/policies.d.mts.map +1 -1
- package/resources/policies.d.ts +2 -1
- package/resources/policies.d.ts.map +1 -1
- package/resources/users.d.mts +35 -24
- package/resources/users.d.mts.map +1 -1
- package/resources/users.d.ts +35 -24
- package/resources/users.d.ts.map +1 -1
- package/resources/users.js +16 -16
- package/resources/users.js.map +1 -1
- package/resources/users.mjs +16 -16
- package/resources/users.mjs.map +1 -1
- package/resources/wallets/wallets.d.mts +3 -18
- package/resources/wallets/wallets.d.mts.map +1 -1
- package/resources/wallets/wallets.d.ts +3 -18
- package/resources/wallets/wallets.d.ts.map +1 -1
- package/resources/wallets/wallets.js.map +1 -1
- package/resources/wallets/wallets.mjs.map +1 -1
- package/src/client.ts +4 -4
- package/src/index.ts +15 -0
- package/src/internal/utils/values.ts +3 -3
- package/src/lib/auth.ts +210 -0
- package/src/lib/identity-token.ts +280 -0
- package/src/lib/user-utils.ts +31 -0
- package/src/public-api/PrivyClient.ts +12 -2
- package/src/public-api/services/ethereum.ts +0 -8
- package/src/public-api/services/solana.ts +0 -4
- package/src/public-api/services/users.ts +36 -2
- package/src/public-api/services/utils/auth.ts +41 -0
- package/src/public-api/services/utils/request-formatter.ts +6 -0
- package/src/public-api/services/utils/request-signer.ts +35 -0
- package/src/public-api/services/utils.ts +21 -31
- package/src/resources/index.ts +1 -1
- package/src/resources/policies.ts +2 -1
- package/src/resources/users.ts +50 -29
- package/src/resources/wallets/wallets.ts +6 -30
- package/src/version.ts +1 -1
- package/src/viem.ts +223 -0
- package/version.d.mts +1 -1
- package/version.d.mts.map +1 -1
- package/version.d.ts +1 -1
- package/version.d.ts.map +1 -1
- package/version.js +1 -1
- package/version.js.map +1 -1
- package/version.mjs +1 -1
- package/version.mjs.map +1 -1
- package/viem.d.mts +22 -0
- package/viem.d.mts.map +1 -0
- package/viem.d.ts +22 -0
- package/viem.d.ts.map +1 -0
- package/viem.js +183 -0
- package/viem.js.map +1 -0
- package/viem.mjs +180 -0
- package/viem.mjs.map +1 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { generateAuthorizationSignature, generateAuthorizationSignatures } from '../../../lib/authorization';
|
|
2
|
+
import { PrivyClient } from '../../PrivyClient';
|
|
3
|
+
|
|
4
|
+
export class PrivyRequestSigner {
|
|
5
|
+
private privyClient: PrivyClient;
|
|
6
|
+
|
|
7
|
+
constructor(privyClient: PrivyClient) {
|
|
8
|
+
this.privyClient = privyClient;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Expose these as methods here for convenience
|
|
12
|
+
public generateAuthorizationSignature = generateAuthorizationSignature;
|
|
13
|
+
public generateAuthorizationSignatures(...input: PrivyRequestSigner.GenerateAuthorizationSignaturesInput) {
|
|
14
|
+
// Pre-populates the client instance for the function
|
|
15
|
+
return generateAuthorizationSignatures(this.privyClient, ...input);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// prettier-ignore
|
|
20
|
+
export namespace PrivyRequestSigner {
|
|
21
|
+
export type GenerateAuthorizationSignaturesInput = ParametersExceptFirst<typeof generateAuthorizationSignatures>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Utility type similar to `Parameters` but excluding the first argument.
|
|
26
|
+
* This is used to get the types of the remaining arguments of a function, excluding the first one.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* type MyFunction = (arg0: string, arg1: number, arg2: boolean) => any;
|
|
31
|
+
* type MyFunctionParameters = ParametersExceptFirst<MyFunction>;
|
|
32
|
+
* // type MyFunctionParameters = [number, boolean]
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
type ParametersExceptFirst<F> = F extends (arg0: any, ...rest: infer R) => any ? R : never;
|
|
@@ -1,40 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
generateAuthorizationSignature,
|
|
4
|
-
generateAuthorizationSignatures,
|
|
5
|
-
} from '../../lib/authorization';
|
|
1
|
+
import { PrivyAppJWKS } from '../../lib/auth';
|
|
2
|
+
import { PrivyAPI } from '../../client';
|
|
6
3
|
import { PrivyClient } from '../PrivyClient';
|
|
4
|
+
import { PrivyAuthUtils } from './utils/auth';
|
|
5
|
+
import { PrivyRequestFormatter } from './utils/request-formatter';
|
|
6
|
+
import { PrivyRequestSigner } from './utils/request-signer';
|
|
7
7
|
|
|
8
8
|
export class PrivyUtils {
|
|
9
|
-
private
|
|
9
|
+
private _requestSigner: PrivyRequestSigner;
|
|
10
|
+
private _requestFormatter: PrivyRequestFormatter;
|
|
11
|
+
private _auth: PrivyAuthUtils;
|
|
10
12
|
|
|
11
|
-
constructor(privyClient: PrivyClient) {
|
|
12
|
-
this.
|
|
13
|
+
constructor(privyApiClient: PrivyAPI, privyClient: PrivyClient, appJwks: PrivyAppJWKS) {
|
|
14
|
+
this._requestSigner = new PrivyRequestSigner(privyClient);
|
|
15
|
+
this._requestFormatter = new PrivyRequestFormatter();
|
|
16
|
+
this._auth = new PrivyAuthUtils(privyApiClient, appJwks);
|
|
13
17
|
}
|
|
14
18
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
public generateAuthorizationSignature = generateAuthorizationSignature;
|
|
18
|
-
public generateAuthorizationSignatures(...input: PrivyUtils.GenerateAuthorizationSignaturesInput) {
|
|
19
|
-
// Pre-populates the client instance for the function
|
|
20
|
-
return generateAuthorizationSignatures(this.privyClient, ...input);
|
|
19
|
+
public requestSigner(): PrivyRequestSigner {
|
|
20
|
+
return this._requestSigner;
|
|
21
21
|
}
|
|
22
|
-
}
|
|
23
22
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
23
|
+
public requestFormatter(): PrivyRequestFormatter {
|
|
24
|
+
return this._requestFormatter;
|
|
25
|
+
}
|
|
28
26
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
* @example
|
|
34
|
-
* ```ts
|
|
35
|
-
* type MyFunction = (arg0: string, arg1: number, arg2: boolean) => any;
|
|
36
|
-
* type MyFunctionParameters = ParametersExceptFirst<MyFunction>;
|
|
37
|
-
* // type MyFunctionParameters = [number, boolean]
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
type ParametersExceptFirst<F> = F extends (arg0: any, ...rest: infer R) => any ? R : never;
|
|
27
|
+
public auth(): PrivyAuthUtils {
|
|
28
|
+
return this._auth;
|
|
29
|
+
}
|
|
30
|
+
}
|
package/src/resources/index.ts
CHANGED
|
@@ -30,7 +30,6 @@ export {
|
|
|
30
30
|
type User,
|
|
31
31
|
type UserCreateParams,
|
|
32
32
|
type UserListParams,
|
|
33
|
-
type UserCreateCustomMetadataParams,
|
|
34
33
|
type UserGetByCustomAuthIDParams,
|
|
35
34
|
type UserGetByDiscordUsernameParams,
|
|
36
35
|
type UserGetByEmailAddressParams,
|
|
@@ -45,6 +44,7 @@ export {
|
|
|
45
44
|
type UserGetByWalletAddressParams,
|
|
46
45
|
type UserPregenerateWalletsParams,
|
|
47
46
|
type UserSearchParams,
|
|
47
|
+
type UserSetCustomMetadataParams,
|
|
48
48
|
type UserUnlinkLinkedAccountParams,
|
|
49
49
|
type UsersCursor,
|
|
50
50
|
} from './users';
|
|
@@ -290,7 +290,8 @@ export interface Policy {
|
|
|
290
290
|
|
|
291
291
|
export namespace Policy {
|
|
292
292
|
/**
|
|
293
|
-
*
|
|
293
|
+
* A rule that defines the conditions and action to take if the conditions are
|
|
294
|
+
* true.
|
|
294
295
|
*/
|
|
295
296
|
export interface Rule {
|
|
296
297
|
id: string;
|
package/src/resources/users.ts
CHANGED
|
@@ -58,34 +58,15 @@ export class Users extends APIResource {
|
|
|
58
58
|
});
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
/**
|
|
62
|
-
* Adds custom metadata to a user by user ID.
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* ```ts
|
|
66
|
-
* const user = await client.users.createCustomMetadata(
|
|
67
|
-
* 'user_id',
|
|
68
|
-
* { custom_metadata: { key: 'value' } },
|
|
69
|
-
* );
|
|
70
|
-
* ```
|
|
71
|
-
*/
|
|
72
|
-
createCustomMetadata(
|
|
73
|
-
userID: string,
|
|
74
|
-
body: UserCreateCustomMetadataParams,
|
|
75
|
-
options?: RequestOptions,
|
|
76
|
-
): APIPromise<User> {
|
|
77
|
-
return this._client.post(path`/v1/users/${userID}/custom_metadata`, { body, ...options });
|
|
78
|
-
}
|
|
79
|
-
|
|
80
61
|
/**
|
|
81
62
|
* Get a user by user ID.
|
|
82
63
|
*
|
|
83
64
|
* @example
|
|
84
65
|
* ```ts
|
|
85
|
-
* const user = await client.users.
|
|
66
|
+
* const user = await client.users._get('user_id');
|
|
86
67
|
* ```
|
|
87
68
|
*/
|
|
88
|
-
|
|
69
|
+
_get(userID: string, options?: RequestOptions): APIPromise<User> {
|
|
89
70
|
return this._client.get(path`/v1/users/${userID}`, options);
|
|
90
71
|
}
|
|
91
72
|
|
|
@@ -293,6 +274,25 @@ export class Users extends APIResource {
|
|
|
293
274
|
return this._client.post('/v1/users/search', { body, ...options });
|
|
294
275
|
}
|
|
295
276
|
|
|
277
|
+
/**
|
|
278
|
+
* Adds custom metadata to a user by user ID.
|
|
279
|
+
*
|
|
280
|
+
* @example
|
|
281
|
+
* ```ts
|
|
282
|
+
* const user = await client.users.setCustomMetadata(
|
|
283
|
+
* 'user_id',
|
|
284
|
+
* { custom_metadata: { key: 'value' } },
|
|
285
|
+
* );
|
|
286
|
+
* ```
|
|
287
|
+
*/
|
|
288
|
+
setCustomMetadata(
|
|
289
|
+
userID: string,
|
|
290
|
+
body: UserSetCustomMetadataParams,
|
|
291
|
+
options?: RequestOptions,
|
|
292
|
+
): APIPromise<User> {
|
|
293
|
+
return this._client.post(path`/v1/users/${userID}/custom_metadata`, { body, ...options });
|
|
294
|
+
}
|
|
295
|
+
|
|
296
296
|
/**
|
|
297
297
|
* Unlinks a user linked account.
|
|
298
298
|
*
|
|
@@ -352,6 +352,7 @@ export interface User {
|
|
|
352
352
|
| User.LinkedAccountSmartWallet
|
|
353
353
|
| User.LinkedAccountPasskey
|
|
354
354
|
| User.LinkedAccountFarcaster
|
|
355
|
+
| User.LinkedAccountTelegram
|
|
355
356
|
| User.LinkedAccountEthereum
|
|
356
357
|
| User.LinkedAccountEthereumEmbeddedWallet
|
|
357
358
|
| User.LinkedAccountSolana
|
|
@@ -685,6 +686,26 @@ export namespace User {
|
|
|
685
686
|
username?: string;
|
|
686
687
|
}
|
|
687
688
|
|
|
689
|
+
export interface LinkedAccountTelegram {
|
|
690
|
+
first_verified_at: number | null;
|
|
691
|
+
|
|
692
|
+
latest_verified_at: number | null;
|
|
693
|
+
|
|
694
|
+
telegram_user_id: string;
|
|
695
|
+
|
|
696
|
+
type: 'telegram';
|
|
697
|
+
|
|
698
|
+
verified_at: number;
|
|
699
|
+
|
|
700
|
+
first_name?: string | null;
|
|
701
|
+
|
|
702
|
+
last_name?: string | null;
|
|
703
|
+
|
|
704
|
+
photo_url?: string | null;
|
|
705
|
+
|
|
706
|
+
username?: string | null;
|
|
707
|
+
}
|
|
708
|
+
|
|
688
709
|
export interface LinkedAccountEthereum {
|
|
689
710
|
address: string;
|
|
690
711
|
|
|
@@ -1152,13 +1173,6 @@ export namespace UserCreateParams {
|
|
|
1152
1173
|
|
|
1153
1174
|
export interface UserListParams extends CursorParams {}
|
|
1154
1175
|
|
|
1155
|
-
export interface UserCreateCustomMetadataParams {
|
|
1156
|
-
/**
|
|
1157
|
-
* Custom metadata associated with the user.
|
|
1158
|
-
*/
|
|
1159
|
-
custom_metadata: { [key: string]: string | number | boolean };
|
|
1160
|
-
}
|
|
1161
|
-
|
|
1162
1176
|
export interface UserGetByCustomAuthIDParams {
|
|
1163
1177
|
custom_user_id: string;
|
|
1164
1178
|
}
|
|
@@ -1258,6 +1272,13 @@ export declare namespace UserSearchParams {
|
|
|
1258
1272
|
}
|
|
1259
1273
|
}
|
|
1260
1274
|
|
|
1275
|
+
export interface UserSetCustomMetadataParams {
|
|
1276
|
+
/**
|
|
1277
|
+
* Custom metadata associated with the user.
|
|
1278
|
+
*/
|
|
1279
|
+
custom_metadata: { [key: string]: string | number | boolean };
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1261
1282
|
export interface UserUnlinkLinkedAccountParams {
|
|
1262
1283
|
handle: string;
|
|
1263
1284
|
|
|
@@ -1292,7 +1313,6 @@ export declare namespace Users {
|
|
|
1292
1313
|
type UsersCursor as UsersCursor,
|
|
1293
1314
|
type UserCreateParams as UserCreateParams,
|
|
1294
1315
|
type UserListParams as UserListParams,
|
|
1295
|
-
type UserCreateCustomMetadataParams as UserCreateCustomMetadataParams,
|
|
1296
1316
|
type UserGetByCustomAuthIDParams as UserGetByCustomAuthIDParams,
|
|
1297
1317
|
type UserGetByDiscordUsernameParams as UserGetByDiscordUsernameParams,
|
|
1298
1318
|
type UserGetByEmailAddressParams as UserGetByEmailAddressParams,
|
|
@@ -1307,6 +1327,7 @@ export declare namespace Users {
|
|
|
1307
1327
|
type UserGetByWalletAddressParams as UserGetByWalletAddressParams,
|
|
1308
1328
|
type UserPregenerateWalletsParams as UserPregenerateWalletsParams,
|
|
1309
1329
|
type UserSearchParams as UserSearchParams,
|
|
1330
|
+
type UserSetCustomMetadataParams as UserSetCustomMetadataParams,
|
|
1310
1331
|
type UserUnlinkLinkedAccountParams as UserUnlinkLinkedAccountParams,
|
|
1311
1332
|
};
|
|
1312
1333
|
}
|
|
@@ -410,11 +410,9 @@ export namespace WalletRpcResponse {
|
|
|
410
410
|
}
|
|
411
411
|
|
|
412
412
|
export interface SolanaSignAndSendTransactionRpcResponse {
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
data?: SolanaSignAndSendTransactionRpcResponse.Data;
|
|
413
|
+
data: SolanaSignAndSendTransactionRpcResponse.Data;
|
|
416
414
|
|
|
417
|
-
|
|
415
|
+
method: 'signAndSendTransaction';
|
|
418
416
|
}
|
|
419
417
|
|
|
420
418
|
export namespace SolanaSignAndSendTransactionRpcResponse {
|
|
@@ -425,12 +423,6 @@ export namespace WalletRpcResponse {
|
|
|
425
423
|
|
|
426
424
|
transaction_id?: string;
|
|
427
425
|
}
|
|
428
|
-
|
|
429
|
-
export interface Error {
|
|
430
|
-
code: string;
|
|
431
|
-
|
|
432
|
-
message: string;
|
|
433
|
-
}
|
|
434
426
|
}
|
|
435
427
|
|
|
436
428
|
export interface SolanaSignMessageRpcResponse {
|
|
@@ -462,11 +454,9 @@ export namespace WalletRpcResponse {
|
|
|
462
454
|
}
|
|
463
455
|
|
|
464
456
|
export interface EthereumSendTransactionRpcResponse {
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
data?: EthereumSendTransactionRpcResponse.Data;
|
|
457
|
+
data: EthereumSendTransactionRpcResponse.Data;
|
|
468
458
|
|
|
469
|
-
|
|
459
|
+
method: 'eth_sendTransaction';
|
|
470
460
|
}
|
|
471
461
|
|
|
472
462
|
export namespace EthereumSendTransactionRpcResponse {
|
|
@@ -505,12 +495,6 @@ export namespace WalletRpcResponse {
|
|
|
505
495
|
value?: string | number;
|
|
506
496
|
}
|
|
507
497
|
}
|
|
508
|
-
|
|
509
|
-
export interface Error {
|
|
510
|
-
code: string;
|
|
511
|
-
|
|
512
|
-
message: string;
|
|
513
|
-
}
|
|
514
498
|
}
|
|
515
499
|
|
|
516
500
|
export interface EthereumPersonalSignRpcResponse {
|
|
@@ -542,11 +526,9 @@ export namespace WalletRpcResponse {
|
|
|
542
526
|
}
|
|
543
527
|
|
|
544
528
|
export interface EthereumSign7702AuthorizationRpcResponse {
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
data?: EthereumSign7702AuthorizationRpcResponse.Data;
|
|
529
|
+
data: EthereumSign7702AuthorizationRpcResponse.Data;
|
|
548
530
|
|
|
549
|
-
|
|
531
|
+
method: 'eth_sign7702Authorization';
|
|
550
532
|
}
|
|
551
533
|
|
|
552
534
|
export namespace EthereumSign7702AuthorizationRpcResponse {
|
|
@@ -569,12 +551,6 @@ export namespace WalletRpcResponse {
|
|
|
569
551
|
y_parity: number;
|
|
570
552
|
}
|
|
571
553
|
}
|
|
572
|
-
|
|
573
|
-
export interface Error {
|
|
574
|
-
code: string;
|
|
575
|
-
|
|
576
|
-
message: string;
|
|
577
|
-
}
|
|
578
554
|
}
|
|
579
555
|
|
|
580
556
|
export interface EthereumSecp256k1SignRpcResponse {
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.1.0
|
|
1
|
+
export const VERSION = '0.1.0'; // x-release-please-version
|
package/src/viem.ts
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import type { Hex } from 'viem';
|
|
2
|
+
import {
|
|
3
|
+
type LocalAccount,
|
|
4
|
+
type SignMessageParameters,
|
|
5
|
+
type SignTransactionParameters,
|
|
6
|
+
toAccount,
|
|
7
|
+
} from 'viem/accounts';
|
|
8
|
+
import { toHex } from 'viem/utils';
|
|
9
|
+
import { PrivyAPIError } from './core/error';
|
|
10
|
+
import type { AuthorizationContext } from './lib/authorization';
|
|
11
|
+
import type { PrivyClient } from './public-api/PrivyClient';
|
|
12
|
+
import type { WalletRpcParams } from './resources';
|
|
13
|
+
|
|
14
|
+
export interface CreateViemAccountInput {
|
|
15
|
+
/** ID for the wallet. */
|
|
16
|
+
walletId: string;
|
|
17
|
+
/** Ethereum address for the wallet. */
|
|
18
|
+
address: Hex;
|
|
19
|
+
/** Authorization context for the wallet. */
|
|
20
|
+
authorizationContext?: AuthorizationContext;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Creates a viem `Account` instance for a Privy wallet given its ID, which can be used to sign
|
|
25
|
+
* messages and send transactions with the wallet.
|
|
26
|
+
*
|
|
27
|
+
* @param client instance of the Privy client.
|
|
28
|
+
* @param input an object specifying the details of the wallet to create the viem account for.
|
|
29
|
+
* @returns viem `Account` instance for the wallet.
|
|
30
|
+
*/
|
|
31
|
+
export function createViemAccount(
|
|
32
|
+
client: PrivyClient,
|
|
33
|
+
{ walletId, address, authorizationContext }: CreateViemAccountInput,
|
|
34
|
+
): LocalAccount {
|
|
35
|
+
return toAccount({
|
|
36
|
+
address: address as Hex,
|
|
37
|
+
sign: async ({ hash }) => {
|
|
38
|
+
const response = await client
|
|
39
|
+
.wallets()
|
|
40
|
+
.ethereum()
|
|
41
|
+
.signSecp256k1(walletId, {
|
|
42
|
+
params: { hash },
|
|
43
|
+
...(authorizationContext ? { authorization_context: authorizationContext } : {}),
|
|
44
|
+
});
|
|
45
|
+
return response.signature as `0x${string}`;
|
|
46
|
+
},
|
|
47
|
+
signMessage: async ({ message }) => {
|
|
48
|
+
const response = await client
|
|
49
|
+
.wallets()
|
|
50
|
+
.ethereum()
|
|
51
|
+
.signMessage(walletId, {
|
|
52
|
+
message: formatViemPersonalSignMessage(message),
|
|
53
|
+
...(authorizationContext ? { authorization_context: authorizationContext } : {}),
|
|
54
|
+
});
|
|
55
|
+
return response.signature as `0x${string}`;
|
|
56
|
+
},
|
|
57
|
+
signTypedData: async (typedData) => {
|
|
58
|
+
const { message, domain, types, primaryType } = replaceBigInts(typedData, toHex);
|
|
59
|
+
// Viem accepts undefined `domain`, `message`, and `types` in this method
|
|
60
|
+
// though those are required per the EIP712 spec.
|
|
61
|
+
if (!domain) throw new PrivyAPIError('typedData.domain must be defined');
|
|
62
|
+
if (!message) throw new PrivyAPIError('typedData.message must be defined');
|
|
63
|
+
if (!types) throw new PrivyAPIError('typedData.message must be defined');
|
|
64
|
+
const { signature } = await client
|
|
65
|
+
.wallets()
|
|
66
|
+
.ethereum()
|
|
67
|
+
.signTypedData(walletId, {
|
|
68
|
+
params: {
|
|
69
|
+
typed_data: { domain, message, primary_type: primaryType as string, types: types as any },
|
|
70
|
+
},
|
|
71
|
+
...(authorizationContext ? { authorization_context: authorizationContext } : {}),
|
|
72
|
+
});
|
|
73
|
+
return signature as Hex;
|
|
74
|
+
},
|
|
75
|
+
signTransaction: async (transaction) => {
|
|
76
|
+
const { signed_transaction: signedTransaction } = await client
|
|
77
|
+
.wallets()
|
|
78
|
+
.ethereum()
|
|
79
|
+
.signTransaction(walletId, {
|
|
80
|
+
params: { transaction: formatViemTransaction(transaction) },
|
|
81
|
+
...(authorizationContext ? { authorization_context: authorizationContext } : {}),
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
return signedTransaction as Hex;
|
|
85
|
+
},
|
|
86
|
+
signAuthorization: async (parameters) => {
|
|
87
|
+
const { authorization } = await client
|
|
88
|
+
.wallets()
|
|
89
|
+
.ethereum()
|
|
90
|
+
.sign7702Authorization(walletId, {
|
|
91
|
+
params: {
|
|
92
|
+
contract: (parameters.contractAddress ?? parameters.address) as Hex,
|
|
93
|
+
chain_id: parameters.chainId,
|
|
94
|
+
nonce: parameters.nonce,
|
|
95
|
+
},
|
|
96
|
+
...(authorizationContext ? { authorization_context: authorizationContext } : {}),
|
|
97
|
+
});
|
|
98
|
+
return {
|
|
99
|
+
address: authorization.contract as Hex,
|
|
100
|
+
nonce: Number(authorization.nonce),
|
|
101
|
+
chainId: Number(authorization.chain_id),
|
|
102
|
+
yParity: authorization.y_parity,
|
|
103
|
+
r: authorization.r as Hex,
|
|
104
|
+
s: authorization.s as Hex,
|
|
105
|
+
};
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Formats a viem transaction type to the JSON-RPC transaction type:
|
|
112
|
+
* - 'legacy' -> 0
|
|
113
|
+
* - 'eip2930' -> 1
|
|
114
|
+
* - 'eip1559' or undefined -> 2. This is the default EVM transaction type.
|
|
115
|
+
* - 'eip4844' -> 3 in theory, but will throw an error as we do not support this yet.
|
|
116
|
+
* - 'eip7702' -> 4 in theory, but will throw an error as we do not support this yet
|
|
117
|
+
* @param type viem transaction type
|
|
118
|
+
* @returns 0 | 1 | 2
|
|
119
|
+
*/
|
|
120
|
+
const formatViemTransactionType = (type: SignTransactionParameters['transaction']['type']) => {
|
|
121
|
+
if (type === 'legacy') {
|
|
122
|
+
return 0 as const;
|
|
123
|
+
} else if (type === 'eip2930') {
|
|
124
|
+
return 1 as const;
|
|
125
|
+
} else if (type == 'eip1559' || typeof type === 'undefined') {
|
|
126
|
+
// Type 2 (EIP-1559) is the default transaction type
|
|
127
|
+
return 2 as const;
|
|
128
|
+
} else {
|
|
129
|
+
// We do not yet support EIP4844 (type 3) and EIP7702 (type 4) transaction types
|
|
130
|
+
throw new PrivyAPIError('EIP4844 and EIP7702 transaction types are not yet supported.');
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Formats viem quantities, which are represented as `bigint | undefined` to our internal
|
|
136
|
+
* `Quantity` type. This is done by converting bigints into a hexstring.
|
|
137
|
+
*
|
|
138
|
+
* @param input {bigint | undefined} bigint quantity to format
|
|
139
|
+
* @returns input as hex string
|
|
140
|
+
*/
|
|
141
|
+
const formatViemQuantity = (input: bigint): Hex => {
|
|
142
|
+
return `0x${input.toString(16)}` as Hex;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Formats a `message` input to viem's `signMessage` function to the format needed for our wallet API.
|
|
147
|
+
*
|
|
148
|
+
* If the `message` is a string, we use it directly.
|
|
149
|
+
*
|
|
150
|
+
* If the `message` is an object containing a `raw` field, it indicates that the use case is signing raw bytes,
|
|
151
|
+
* in which case we convert `message.raw` into a `Uint8Array` before passing it to our own `signMessage`
|
|
152
|
+
* @param message input to viem's `signMessage` function
|
|
153
|
+
* @returns message as a utf-8 `string` or `Uint8Array`
|
|
154
|
+
*/
|
|
155
|
+
const formatViemPersonalSignMessage = (message: SignMessageParameters['message']): string | Uint8Array => {
|
|
156
|
+
if (typeof message === 'string') return message;
|
|
157
|
+
|
|
158
|
+
if (typeof message.raw === 'string') {
|
|
159
|
+
// We `.slice(2)` to remove the `0x` prefix
|
|
160
|
+
return Uint8Array.from(Buffer.from(message.raw.slice(2), 'hex'));
|
|
161
|
+
} else {
|
|
162
|
+
return message.raw;
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Formats a viem transaction into our internal transaction type. For the most part, this converts
|
|
168
|
+
* bigints to hexstrings so they can be passed over the wire.
|
|
169
|
+
*
|
|
170
|
+
* @param tx input to viem's `sendTransaction` function
|
|
171
|
+
* @returns transaction {EthereumSignTransactionInputType} as our own type
|
|
172
|
+
*/
|
|
173
|
+
const formatViemTransaction = (
|
|
174
|
+
tx: SignTransactionParameters['transaction'],
|
|
175
|
+
): WalletRpcParams.EthereumSignTransactionRpcInput.Params.Transaction => {
|
|
176
|
+
return {
|
|
177
|
+
type: formatViemTransactionType(tx.type),
|
|
178
|
+
...(tx.to ? { to: tx.to } : {}),
|
|
179
|
+
...(tx.nonce ? { nonce: tx.nonce } : {}),
|
|
180
|
+
...(tx.chainId ? { chain_id: tx.chainId } : {}),
|
|
181
|
+
...(tx.data ? { data: tx.data } : {}),
|
|
182
|
+
...(tx.value ? { value: formatViemQuantity(tx.value) } : {}),
|
|
183
|
+
...(tx.gas ? { gas_limit: formatViemQuantity(tx.gas) } : {}),
|
|
184
|
+
...(tx.gasPrice ? { gas_price: formatViemQuantity(tx.gasPrice) } : {}),
|
|
185
|
+
...(tx.maxFeePerGas ? { max_fee_per_gas: formatViemQuantity(tx.maxFeePerGas) } : {}),
|
|
186
|
+
...(tx.maxPriorityFeePerGas ?
|
|
187
|
+
{ max_priority_fee_per_gas: formatViemQuantity(tx.maxPriorityFeePerGas) }
|
|
188
|
+
: {}),
|
|
189
|
+
};
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
// replaceBigInts courtesy of ponder.sh:
|
|
193
|
+
// https://github.com/ponder-sh/ponder/blob/bc65b865898b6145e87031314192c59f9e8b621f/packages/utils/src/replaceBigInts.ts
|
|
194
|
+
type _ReplaceBigInts<
|
|
195
|
+
arr extends readonly unknown[],
|
|
196
|
+
type,
|
|
197
|
+
result extends readonly unknown[] = [],
|
|
198
|
+
> = arr extends [infer first, ...infer rest] ?
|
|
199
|
+
_ReplaceBigInts<rest, type, readonly [...result, first extends bigint ? type : first]>
|
|
200
|
+
: result;
|
|
201
|
+
|
|
202
|
+
type ReplaceBigInts<obj, type> =
|
|
203
|
+
obj extends bigint ? type
|
|
204
|
+
: obj extends unknown[] ? _ReplaceBigInts<Readonly<obj>, type>
|
|
205
|
+
: obj extends readonly [] ? _ReplaceBigInts<obj, type>
|
|
206
|
+
: obj extends object ? { [key in keyof obj]: ReplaceBigInts<obj[key], type> }
|
|
207
|
+
: obj;
|
|
208
|
+
|
|
209
|
+
const replaceBigInts = <const T, const type>(
|
|
210
|
+
obj: T,
|
|
211
|
+
replacer: (x: bigint) => type,
|
|
212
|
+
): ReplaceBigInts<T, type> => {
|
|
213
|
+
if (typeof obj === 'bigint') return replacer(obj) as ReplaceBigInts<T, type>;
|
|
214
|
+
if (Array.isArray(obj)) {
|
|
215
|
+
return obj.map((x) => replaceBigInts(x, replacer)) as ReplaceBigInts<T, type>;
|
|
216
|
+
}
|
|
217
|
+
if (obj && typeof obj === 'object') {
|
|
218
|
+
return Object.fromEntries(
|
|
219
|
+
Object.entries(obj).map(([k, v]) => [k, replaceBigInts(v, replacer)]),
|
|
220
|
+
) as ReplaceBigInts<T, type>;
|
|
221
|
+
}
|
|
222
|
+
return obj as ReplaceBigInts<T, type>;
|
|
223
|
+
};
|
package/version.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.1.0
|
|
1
|
+
export declare const VERSION = "0.1.0";
|
|
2
2
|
//# sourceMappingURL=version.d.mts.map
|
package/version.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.mts","sourceRoot":"","sources":["src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"version.d.mts","sourceRoot":"","sources":["src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,UAAU,CAAC"}
|
package/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.1.0
|
|
1
|
+
export declare const VERSION = "0.1.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/version.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["src/version.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,OAAO,UAAU,CAAC"}
|
package/version.js
CHANGED
package/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["src/version.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["src/version.ts"],"names":[],"mappings":";;;AAAa,QAAA,OAAO,GAAG,OAAO,CAAC,CAAC,2BAA2B"}
|
package/version.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = '0.1.0
|
|
1
|
+
export const VERSION = '0.1.0'; // x-release-please-version
|
|
2
2
|
//# sourceMappingURL=version.mjs.map
|
package/version.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.mjs","sourceRoot":"","sources":["src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"version.mjs","sourceRoot":"","sources":["src/version.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC,CAAC,2BAA2B"}
|
package/viem.d.mts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Hex } from 'viem';
|
|
2
|
+
import { type LocalAccount } from 'viem/accounts';
|
|
3
|
+
import type { AuthorizationContext } from "./lib/authorization.mjs";
|
|
4
|
+
import type { PrivyClient } from "./public-api/PrivyClient.mjs";
|
|
5
|
+
export interface CreateViemAccountInput {
|
|
6
|
+
/** ID for the wallet. */
|
|
7
|
+
walletId: string;
|
|
8
|
+
/** Ethereum address for the wallet. */
|
|
9
|
+
address: Hex;
|
|
10
|
+
/** Authorization context for the wallet. */
|
|
11
|
+
authorizationContext?: AuthorizationContext;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Creates a viem `Account` instance for a Privy wallet given its ID, which can be used to sign
|
|
15
|
+
* messages and send transactions with the wallet.
|
|
16
|
+
*
|
|
17
|
+
* @param client instance of the Privy client.
|
|
18
|
+
* @param input an object specifying the details of the wallet to create the viem account for.
|
|
19
|
+
* @returns viem `Account` instance for the wallet.
|
|
20
|
+
*/
|
|
21
|
+
export declare function createViemAccount(client: PrivyClient, { walletId, address, authorizationContext }: CreateViemAccountInput): LocalAccount;
|
|
22
|
+
//# sourceMappingURL=viem.d.mts.map
|
package/viem.d.mts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"viem.d.mts","sourceRoot":"","sources":["src/viem.ts"],"names":[],"mappings":"OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,MAAM;OACxB,EACL,KAAK,YAAY,EAIlB,MAAM,eAAe;OAGf,KAAK,EAAE,oBAAoB,EAAE;OAC7B,KAAK,EAAE,WAAW,EAAE;AAG3B,MAAM,WAAW,sBAAsB;IACrC,yBAAyB;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,uCAAuC;IACvC,OAAO,EAAE,GAAG,CAAC;IACb,4CAA4C;IAC5C,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;CAC7C;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,WAAW,EACnB,EAAE,QAAQ,EAAE,OAAO,EAAE,oBAAoB,EAAE,EAAE,sBAAsB,GAClE,YAAY,CA0Ed"}
|
package/viem.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Hex } from 'viem';
|
|
2
|
+
import { type LocalAccount } from 'viem/accounts';
|
|
3
|
+
import type { AuthorizationContext } from "./lib/authorization.js";
|
|
4
|
+
import type { PrivyClient } from "./public-api/PrivyClient.js";
|
|
5
|
+
export interface CreateViemAccountInput {
|
|
6
|
+
/** ID for the wallet. */
|
|
7
|
+
walletId: string;
|
|
8
|
+
/** Ethereum address for the wallet. */
|
|
9
|
+
address: Hex;
|
|
10
|
+
/** Authorization context for the wallet. */
|
|
11
|
+
authorizationContext?: AuthorizationContext;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Creates a viem `Account` instance for a Privy wallet given its ID, which can be used to sign
|
|
15
|
+
* messages and send transactions with the wallet.
|
|
16
|
+
*
|
|
17
|
+
* @param client instance of the Privy client.
|
|
18
|
+
* @param input an object specifying the details of the wallet to create the viem account for.
|
|
19
|
+
* @returns viem `Account` instance for the wallet.
|
|
20
|
+
*/
|
|
21
|
+
export declare function createViemAccount(client: PrivyClient, { walletId, address, authorizationContext }: CreateViemAccountInput): LocalAccount;
|
|
22
|
+
//# sourceMappingURL=viem.d.ts.map
|
package/viem.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"viem.d.ts","sourceRoot":"","sources":["src/viem.ts"],"names":[],"mappings":"OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,MAAM;OACxB,EACL,KAAK,YAAY,EAIlB,MAAM,eAAe;OAGf,KAAK,EAAE,oBAAoB,EAAE;OAC7B,KAAK,EAAE,WAAW,EAAE;AAG3B,MAAM,WAAW,sBAAsB;IACrC,yBAAyB;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,uCAAuC;IACvC,OAAO,EAAE,GAAG,CAAC;IACb,4CAA4C;IAC5C,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;CAC7C;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,WAAW,EACnB,EAAE,QAAQ,EAAE,OAAO,EAAE,oBAAoB,EAAE,EAAE,sBAAsB,GAClE,YAAY,CA0Ed"}
|