@zerodev/permissions 5.2.3 → 5.2.4
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/_cjs/signers/toRemoteSessionKeySigner.js +26 -24
- package/_cjs/signers/toRemoteSessionKeySigner.js.map +1 -1
- package/_esm/signers/toRemoteSessionKeySigner.js +26 -24
- package/_esm/signers/toRemoteSessionKeySigner.js.map +1 -1
- package/_types/signers/toRemoteSessionKeySigner.d.ts +2 -3
- package/_types/signers/toRemoteSessionKeySigner.d.ts.map +1 -1
- package/package.json +1 -1
- package/signers/toRemoteSessionKeySigner.ts +39 -41
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.toRemoteSessionKeySigner = exports.SessionKeySignerMode = void 0;
|
|
4
4
|
const sdk_1 = require("@zerodev/sdk");
|
|
5
|
-
const axios_1 = require("axios");
|
|
6
5
|
const accounts_1 = require("permissionless/accounts");
|
|
7
6
|
const viem_1 = require("viem");
|
|
8
7
|
const accounts_2 = require("viem/accounts");
|
|
@@ -12,28 +11,28 @@ var SessionKeySignerMode;
|
|
|
12
11
|
SessionKeySignerMode["Create"] = "create";
|
|
13
12
|
SessionKeySignerMode["Get"] = "get";
|
|
14
13
|
})(SessionKeySignerMode || (exports.SessionKeySignerMode = SessionKeySignerMode = {}));
|
|
15
|
-
async function toRemoteSessionKeySigner({
|
|
14
|
+
async function toRemoteSessionKeySigner({ apiKey, walletAddress, sessionKeyStorageUrl = "https://keys.zerodev.app/wallet/v1", mode = SessionKeySignerMode.Get, signerContractAddress = constants_js_1.ECDSA_SIGNER_CONTRACT }) {
|
|
16
15
|
if (mode === SessionKeySignerMode.Create) {
|
|
17
16
|
try {
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
}, {
|
|
17
|
+
const response = await fetch(`${sessionKeyStorageUrl}/key-pair`, {
|
|
18
|
+
method: "POST",
|
|
21
19
|
headers: {
|
|
20
|
+
"Content-Type": "application/json",
|
|
22
21
|
"x-api-key": apiKey
|
|
23
22
|
}
|
|
24
23
|
});
|
|
25
|
-
|
|
24
|
+
if (!response.ok) {
|
|
25
|
+
const errorBody = await response.json();
|
|
26
|
+
throw new Error(`Request failed with status code ${response.status}: ${errorBody.message}`);
|
|
27
|
+
}
|
|
28
|
+
const createTurnkeyWalletResult = await response.json();
|
|
29
|
+
walletAddress = createTurnkeyWalletResult.walletAddress;
|
|
26
30
|
}
|
|
27
31
|
catch (error) {
|
|
28
32
|
const errorMessage = error instanceof Error
|
|
29
33
|
? error.message
|
|
30
34
|
: "An unknown error occurred";
|
|
31
|
-
|
|
32
|
-
throw new Error(`Request failed with status code ${error.response.status}: ${error.response.data.message || errorMessage}`);
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
throw new Error(`An unexpected error occurred: ${errorMessage}`);
|
|
36
|
-
}
|
|
35
|
+
throw new Error(`An unexpected error occurred: ${errorMessage}`);
|
|
37
36
|
}
|
|
38
37
|
}
|
|
39
38
|
if (!walletAddress) {
|
|
@@ -41,26 +40,29 @@ async function toRemoteSessionKeySigner({ userName, apiKey, walletAddress, sessi
|
|
|
41
40
|
}
|
|
42
41
|
const signMessageWithTurnkeyWallet = async (message) => {
|
|
43
42
|
try {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
message
|
|
47
|
-
}, {
|
|
43
|
+
const response = await fetch(`${sessionKeyStorageUrl}/sign-message`, {
|
|
44
|
+
method: "POST",
|
|
48
45
|
headers: {
|
|
46
|
+
"Content-Type": "application/json",
|
|
49
47
|
"x-api-key": apiKey
|
|
50
|
-
}
|
|
48
|
+
},
|
|
49
|
+
body: JSON.stringify({
|
|
50
|
+
walletAddress,
|
|
51
|
+
message
|
|
52
|
+
})
|
|
51
53
|
});
|
|
52
|
-
|
|
54
|
+
if (!response.ok) {
|
|
55
|
+
const errorBody = await response.json();
|
|
56
|
+
throw new Error(`Request failed with status code ${response.status}: ${errorBody.message || "An unknown error occurred"}`);
|
|
57
|
+
}
|
|
58
|
+
const signMessageResult = await response.json();
|
|
59
|
+
return signMessageResult.signature;
|
|
53
60
|
}
|
|
54
61
|
catch (error) {
|
|
55
62
|
const errorMessage = error instanceof Error
|
|
56
63
|
? error.message
|
|
57
64
|
: "An unknown error occurred";
|
|
58
|
-
|
|
59
|
-
throw new Error(`Request failed with status code ${error.response.status}: ${error.response.data.message || errorMessage}`);
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
throw new Error(`An unexpected error occurred: ${errorMessage}`);
|
|
63
|
-
}
|
|
65
|
+
throw new Error(`An unexpected error occurred: ${errorMessage}`);
|
|
64
66
|
}
|
|
65
67
|
};
|
|
66
68
|
const account = (0, accounts_2.toAccount)({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toRemoteSessionKeySigner.js","sourceRoot":"","sources":["../../signers/toRemoteSessionKeySigner.ts"],"names":[],"mappings":";;;AAAA,sCAAuD;AAEvD,
|
|
1
|
+
{"version":3,"file":"toRemoteSessionKeySigner.js","sourceRoot":"","sources":["../../signers/toRemoteSessionKeySigner.ts"],"names":[],"mappings":";;;AAAA,sCAAuD;AAEvD,sDAAmF;AACnF,+BAQa;AACb,4CAAyC;AACzC,kDAAuD;AAGvD,IAAY,oBAGX;AAHD,WAAY,oBAAoB;IAC5B,yCAAiB,CAAA;IACjB,mCAAW,CAAA;AACf,CAAC,EAHW,oBAAoB,oCAApB,oBAAoB,QAG/B;AASM,KAAK,UAAU,wBAAwB,CAAC,EAC3C,MAAM,EACN,aAAa,EACb,oBAAoB,GAAG,oCAAoC,EAC3D,IAAI,GAAG,oBAAoB,CAAC,GAAG,EAC/B,qBAAqB,GAAG,oCAAqB,EACjB;IAC5B,IAAI,IAAI,KAAK,oBAAoB,CAAC,MAAM,EAAE,CAAC;QACvC,IAAI,CAAC;YACD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,oBAAoB,WAAW,EAAE;gBAC7D,MA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A;QAClE,CAAC;KACJ,CAAC,CAAA;IACF,OAAO;QACH,OAAO;QACP,qBAAqB;QACrB,aAAa,EAAE,GAAG,EAAE;YAChB,IAAI,CAAC,aAAa,EAAE,CAAC;gBACjB,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAA;YAC/C,CAAC;YACD,OAAO,aAAa,CAAA;QACxB,CAAC;QACD,iBAAiB,EAAE,GAAG,EAAE,CAAC,eAAS,CAAC,eAAe;KACrD,CAAA;AACL,CAAC;AAnHD,4DAmHC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { constants, fixSignedData } from "@zerodev/sdk";
|
|
2
|
-
import axios from "axios";
|
|
3
2
|
import { SignTransactionNotSupportedBySmartAccount } from "permissionless/accounts";
|
|
4
3
|
import { getTypesForEIP712Domain, hashTypedData, validateTypedData } from "viem";
|
|
5
4
|
import { toAccount } from "viem/accounts";
|
|
@@ -9,28 +8,28 @@ export var SessionKeySignerMode;
|
|
|
9
8
|
SessionKeySignerMode["Create"] = "create";
|
|
10
9
|
SessionKeySignerMode["Get"] = "get";
|
|
11
10
|
})(SessionKeySignerMode || (SessionKeySignerMode = {}));
|
|
12
|
-
export async function toRemoteSessionKeySigner({
|
|
11
|
+
export async function toRemoteSessionKeySigner({ apiKey, walletAddress, sessionKeyStorageUrl = "https://keys.zerodev.app/wallet/v1", mode = SessionKeySignerMode.Get, signerContractAddress = ECDSA_SIGNER_CONTRACT }) {
|
|
13
12
|
if (mode === SessionKeySignerMode.Create) {
|
|
14
13
|
try {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
}, {
|
|
14
|
+
const response = await fetch(`${sessionKeyStorageUrl}/key-pair`, {
|
|
15
|
+
method: "POST",
|
|
18
16
|
headers: {
|
|
17
|
+
"Content-Type": "application/json",
|
|
19
18
|
"x-api-key": apiKey
|
|
20
19
|
}
|
|
21
20
|
});
|
|
22
|
-
|
|
21
|
+
if (!response.ok) {
|
|
22
|
+
const errorBody = await response.json();
|
|
23
|
+
throw new Error(`Request failed with status code ${response.status}: ${errorBody.message}`);
|
|
24
|
+
}
|
|
25
|
+
const createTurnkeyWalletResult = await response.json();
|
|
26
|
+
walletAddress = createTurnkeyWalletResult.walletAddress;
|
|
23
27
|
}
|
|
24
28
|
catch (error) {
|
|
25
29
|
const errorMessage = error instanceof Error
|
|
26
30
|
? error.message
|
|
27
31
|
: "An unknown error occurred";
|
|
28
|
-
|
|
29
|
-
throw new Error(`Request failed with status code ${error.response.status}: ${error.response.data.message || errorMessage}`);
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
throw new Error(`An unexpected error occurred: ${errorMessage}`);
|
|
33
|
-
}
|
|
32
|
+
throw new Error(`An unexpected error occurred: ${errorMessage}`);
|
|
34
33
|
}
|
|
35
34
|
}
|
|
36
35
|
if (!walletAddress) {
|
|
@@ -38,26 +37,29 @@ export async function toRemoteSessionKeySigner({ userName, apiKey, walletAddress
|
|
|
38
37
|
}
|
|
39
38
|
const signMessageWithTurnkeyWallet = async (message) => {
|
|
40
39
|
try {
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
message
|
|
44
|
-
}, {
|
|
40
|
+
const response = await fetch(`${sessionKeyStorageUrl}/sign-message`, {
|
|
41
|
+
method: "POST",
|
|
45
42
|
headers: {
|
|
43
|
+
"Content-Type": "application/json",
|
|
46
44
|
"x-api-key": apiKey
|
|
47
|
-
}
|
|
45
|
+
},
|
|
46
|
+
body: JSON.stringify({
|
|
47
|
+
walletAddress,
|
|
48
|
+
message
|
|
49
|
+
})
|
|
48
50
|
});
|
|
49
|
-
|
|
51
|
+
if (!response.ok) {
|
|
52
|
+
const errorBody = await response.json();
|
|
53
|
+
throw new Error(`Request failed with status code ${response.status}: ${errorBody.message || "An unknown error occurred"}`);
|
|
54
|
+
}
|
|
55
|
+
const signMessageResult = await response.json();
|
|
56
|
+
return signMessageResult.signature;
|
|
50
57
|
}
|
|
51
58
|
catch (error) {
|
|
52
59
|
const errorMessage = error instanceof Error
|
|
53
60
|
? error.message
|
|
54
61
|
: "An unknown error occurred";
|
|
55
|
-
|
|
56
|
-
throw new Error(`Request failed with status code ${error.response.status}: ${error.response.data.message || errorMessage}`);
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
throw new Error(`An unexpected error occurred: ${errorMessage}`);
|
|
60
|
-
}
|
|
62
|
+
throw new Error(`An unexpected error occurred: ${errorMessage}`);
|
|
61
63
|
}
|
|
62
64
|
};
|
|
63
65
|
const account = toAccount({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toRemoteSessionKeySigner.js","sourceRoot":"","sources":["../../signers/toRemoteSessionKeySigner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAEvD,OAAO,
|
|
1
|
+
{"version":3,"file":"toRemoteSessionKeySigner.js","sourceRoot":"","sources":["../../signers/toRemoteSessionKeySigner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAEvD,OAAO,EAAE,yCAAyC,EAAE,MAAM,yBAAyB,CAAA;AACnF,OAAO,EAKH,uBAAuB,EACvB,aAAa,EACb,iBAAiB,EACpB,MAAM,MAAM,CAAA;AACb,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AACzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AAGvD,MAAM,CAAN,IAAY,oBAGX;AAHD,WAAY,oBAAoB;IAC5B,yCAAiB,CAAA;IACjB,mCAAW,CAAA;AACf,CAAC,EAHW,oBAAoB,KAApB,oBAAoB,QAG/B;AASD,MAAM,CAAC,KAAK,UAAU,wBAAwB,CAAC,EAC3C,MAAM,EACN,aAAa,EACb,oBAAoB,GAAG,oCAAoC,EAC3D,IAAI,GAAG,oBAAoB,CAAC,GAAG,EAC/B,qBAAqB,GAAG,qBAAqB,EACjB;IAC5B,IAAI,IAAI,KAAK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CAAC,SAAS,CAAC,CAAA;YACrC,OAAO,aAAa,CAAC,MAAM,4BAA4B,CAAC,IAAI,CAAC,CAAC,CAAA;QAClE,CAAC;KACJ,CAAC,CAAA;IACF,OAAO;QACH,OAAO;QACP,qBAAqB;QACrB,aAAa,EAAE,GAAG,EAAE;YAChB,IAAI,CAAC,aAAa,EAAE,CAAC;gBACjB,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAA;YAC/C,CAAC;YACD,OAAO,aAAa,CAAA;QACxB,CAAC;QACD,iBAAiB,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,eAAe;KACrD,CAAA;AACL,CAAC"}
|
|
@@ -5,11 +5,10 @@ export declare enum SessionKeySignerMode {
|
|
|
5
5
|
Get = "get"
|
|
6
6
|
}
|
|
7
7
|
export type SessionKeyModularSignerParams = ModularSignerParams & {
|
|
8
|
-
userName: string;
|
|
9
8
|
apiKey: string;
|
|
10
|
-
sessionKeyStorageUrl
|
|
9
|
+
sessionKeyStorageUrl?: string;
|
|
11
10
|
walletAddress?: Hex;
|
|
12
11
|
mode?: SessionKeySignerMode;
|
|
13
12
|
};
|
|
14
|
-
export declare function toRemoteSessionKeySigner({
|
|
13
|
+
export declare function toRemoteSessionKeySigner({ apiKey, walletAddress, sessionKeyStorageUrl, mode, signerContractAddress }: SessionKeyModularSignerParams): Promise<ModularSigner>;
|
|
15
14
|
//# sourceMappingURL=toRemoteSessionKeySigner.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toRemoteSessionKeySigner.d.ts","sourceRoot":"","sources":["../../signers/toRemoteSessionKeySigner.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"toRemoteSessionKeySigner.d.ts","sourceRoot":"","sources":["../../signers/toRemoteSessionKeySigner.ts"],"names":[],"mappings":"AAGA,OAAO,EACH,KAAK,GAAG,EAOX,MAAM,MAAM,CAAA;AAGb,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAErE,oBAAY,oBAAoB;IAC5B,MAAM,WAAW;IACjB,GAAG,QAAQ;CACd;AAED,MAAM,MAAM,6BAA6B,GAAG,mBAAmB,GAAG;IAC9D,MAAM,EAAE,MAAM,CAAA;IACd,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAC7B,aAAa,CAAC,EAAE,GAAG,CAAA;IACnB,IAAI,CAAC,EAAE,oBAAoB,CAAA;CAC9B,CAAA;AAED,wBAAsB,wBAAwB,CAAC,EAC3C,MAAM,EACN,aAAa,EACb,oBAA2D,EAC3D,IAA+B,EAC/B,qBAA6C,EAChD,EAAE,6BAA6B,GAAG,OAAO,CAAC,aAAa,CAAC,CA6GxD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { constants, fixSignedData } from "@zerodev/sdk"
|
|
2
2
|
import type { TypedData } from "abitype"
|
|
3
|
-
import axios from "axios"
|
|
4
3
|
import { SignTransactionNotSupportedBySmartAccount } from "permissionless/accounts"
|
|
5
4
|
import {
|
|
6
5
|
type Hex,
|
|
@@ -21,49 +20,44 @@ export enum SessionKeySignerMode {
|
|
|
21
20
|
}
|
|
22
21
|
|
|
23
22
|
export type SessionKeyModularSignerParams = ModularSignerParams & {
|
|
24
|
-
userName: string
|
|
25
23
|
apiKey: string
|
|
26
|
-
sessionKeyStorageUrl
|
|
24
|
+
sessionKeyStorageUrl?: string
|
|
27
25
|
walletAddress?: Hex
|
|
28
26
|
mode?: SessionKeySignerMode
|
|
29
27
|
}
|
|
30
28
|
|
|
31
29
|
export async function toRemoteSessionKeySigner({
|
|
32
|
-
userName,
|
|
33
30
|
apiKey,
|
|
34
31
|
walletAddress,
|
|
35
|
-
sessionKeyStorageUrl,
|
|
32
|
+
sessionKeyStorageUrl = "https://keys.zerodev.app/wallet/v1",
|
|
36
33
|
mode = SessionKeySignerMode.Get,
|
|
37
34
|
signerContractAddress = ECDSA_SIGNER_CONTRACT
|
|
38
35
|
}: SessionKeyModularSignerParams): Promise<ModularSigner> {
|
|
39
36
|
if (mode === SessionKeySignerMode.Create) {
|
|
40
37
|
try {
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
{
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
{
|
|
47
|
-
headers: {
|
|
48
|
-
"x-api-key": apiKey
|
|
49
|
-
}
|
|
38
|
+
const response = await fetch(`${sessionKeyStorageUrl}/key-pair`, {
|
|
39
|
+
method: "POST",
|
|
40
|
+
headers: {
|
|
41
|
+
"Content-Type": "application/json",
|
|
42
|
+
"x-api-key": apiKey
|
|
50
43
|
}
|
|
51
|
-
)
|
|
52
|
-
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
if (!response.ok) {
|
|
47
|
+
const errorBody = await response.json()
|
|
48
|
+
throw new Error(
|
|
49
|
+
`Request failed with status code ${response.status}: ${errorBody.message}`
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const createTurnkeyWalletResult = await response.json()
|
|
54
|
+
walletAddress = createTurnkeyWalletResult.walletAddress
|
|
53
55
|
} catch (error) {
|
|
54
56
|
const errorMessage =
|
|
55
57
|
error instanceof Error
|
|
56
58
|
? error.message
|
|
57
59
|
: "An unknown error occurred"
|
|
58
|
-
|
|
59
|
-
throw new Error(
|
|
60
|
-
`Request failed with status code ${
|
|
61
|
-
error.response.status
|
|
62
|
-
}: ${error.response.data.message || errorMessage}`
|
|
63
|
-
)
|
|
64
|
-
} else {
|
|
65
|
-
throw new Error(`An unexpected error occurred: ${errorMessage}`)
|
|
66
|
-
}
|
|
60
|
+
throw new Error(`An unexpected error occurred: ${errorMessage}`)
|
|
67
61
|
}
|
|
68
62
|
}
|
|
69
63
|
|
|
@@ -73,34 +67,38 @@ export async function toRemoteSessionKeySigner({
|
|
|
73
67
|
|
|
74
68
|
const signMessageWithTurnkeyWallet = async (message: SignableMessage) => {
|
|
75
69
|
try {
|
|
76
|
-
const
|
|
70
|
+
const response = await fetch(
|
|
77
71
|
`${sessionKeyStorageUrl}/sign-message`,
|
|
78
72
|
{
|
|
79
|
-
|
|
80
|
-
message
|
|
81
|
-
},
|
|
82
|
-
{
|
|
73
|
+
method: "POST",
|
|
83
74
|
headers: {
|
|
75
|
+
"Content-Type": "application/json",
|
|
84
76
|
"x-api-key": apiKey
|
|
85
|
-
}
|
|
77
|
+
},
|
|
78
|
+
body: JSON.stringify({
|
|
79
|
+
walletAddress,
|
|
80
|
+
message
|
|
81
|
+
})
|
|
86
82
|
}
|
|
87
83
|
)
|
|
88
84
|
|
|
89
|
-
|
|
85
|
+
if (!response.ok) {
|
|
86
|
+
const errorBody = await response.json()
|
|
87
|
+
throw new Error(
|
|
88
|
+
`Request failed with status code ${response.status}: ${
|
|
89
|
+
errorBody.message || "An unknown error occurred"
|
|
90
|
+
}`
|
|
91
|
+
)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const signMessageResult = await response.json()
|
|
95
|
+
return signMessageResult.signature
|
|
90
96
|
} catch (error) {
|
|
91
97
|
const errorMessage =
|
|
92
98
|
error instanceof Error
|
|
93
99
|
? error.message
|
|
94
100
|
: "An unknown error occurred"
|
|
95
|
-
|
|
96
|
-
throw new Error(
|
|
97
|
-
`Request failed with status code ${
|
|
98
|
-
error.response.status
|
|
99
|
-
}: ${error.response.data.message || errorMessage}`
|
|
100
|
-
)
|
|
101
|
-
} else {
|
|
102
|
-
throw new Error(`An unexpected error occurred: ${errorMessage}`)
|
|
103
|
-
}
|
|
101
|
+
throw new Error(`An unexpected error occurred: ${errorMessage}`)
|
|
104
102
|
}
|
|
105
103
|
}
|
|
106
104
|
|