@zerodev/sdk 5.1.6 → 5.1.7
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/providers/KernelEIP1193Provider.js +62 -0
- package/_cjs/providers/KernelEIP1193Provider.js.map +1 -0
- package/_cjs/providers/index.js +6 -0
- package/_cjs/providers/index.js.map +1 -0
- package/_esm/providers/KernelEIP1193Provider.js +60 -0
- package/_esm/providers/KernelEIP1193Provider.js.map +1 -0
- package/_esm/providers/index.js +2 -0
- package/_esm/providers/index.js.map +1 -0
- package/_types/providers/KernelEIP1193Provider.d.ts +14 -0
- package/_types/providers/KernelEIP1193Provider.d.ts.map +1 -0
- package/_types/providers/index.d.ts +2 -0
- package/_types/providers/index.d.ts.map +1 -0
- package/package.json +6 -1
- package/providers/KernelEIP1193Provider.ts +76 -0
- package/providers/index.ts +1 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KernelEIP1193Provider = void 0;
|
|
4
|
+
const events_1 = require("events");
|
|
5
|
+
class KernelEIP1193Provider extends events_1.EventEmitter {
|
|
6
|
+
constructor(kernelClient) {
|
|
7
|
+
super();
|
|
8
|
+
Object.defineProperty(this, "kernelClient", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
configurable: true,
|
|
11
|
+
writable: true,
|
|
12
|
+
value: void 0
|
|
13
|
+
});
|
|
14
|
+
this.kernelClient = kernelClient;
|
|
15
|
+
}
|
|
16
|
+
async request({ method, params = [] }) {
|
|
17
|
+
switch (method) {
|
|
18
|
+
case "eth_requestAccounts":
|
|
19
|
+
return this.handleEthRequestAccounts();
|
|
20
|
+
case "eth_accounts":
|
|
21
|
+
return this.handleEthAccounts();
|
|
22
|
+
case "eth_sendTransaction":
|
|
23
|
+
return this.handleEthSendTransaction(params);
|
|
24
|
+
case "personal_sign":
|
|
25
|
+
return this.handlePersonalSign(params);
|
|
26
|
+
default:
|
|
27
|
+
return this.kernelClient.transport.request({ method, params });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async handleEthRequestAccounts() {
|
|
31
|
+
if (!this.kernelClient.account) {
|
|
32
|
+
return [];
|
|
33
|
+
}
|
|
34
|
+
return [this.kernelClient.account.address];
|
|
35
|
+
}
|
|
36
|
+
async handleEthAccounts() {
|
|
37
|
+
if (!this.kernelClient.account) {
|
|
38
|
+
return [];
|
|
39
|
+
}
|
|
40
|
+
return [this.kernelClient.account.address];
|
|
41
|
+
}
|
|
42
|
+
async handleEthSendTransaction(params) {
|
|
43
|
+
const [tx] = params;
|
|
44
|
+
return this.kernelClient.sendTransaction(tx);
|
|
45
|
+
}
|
|
46
|
+
async handlePersonalSign(params) {
|
|
47
|
+
if (!this.kernelClient?.account) {
|
|
48
|
+
throw new Error("account not connected!");
|
|
49
|
+
}
|
|
50
|
+
const [message, address] = params;
|
|
51
|
+
if (address.toLowerCase() !==
|
|
52
|
+
this.kernelClient.account.address.toLowerCase()) {
|
|
53
|
+
throw new Error("cannot sign for address that is not the current account");
|
|
54
|
+
}
|
|
55
|
+
return this.kernelClient.signMessage({
|
|
56
|
+
message,
|
|
57
|
+
account: this.kernelClient.account
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.KernelEIP1193Provider = KernelEIP1193Provider;
|
|
62
|
+
//# sourceMappingURL=KernelEIP1193Provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KernelEIP1193Provider.js","sourceRoot":"","sources":["../../providers/KernelEIP1193Provider.ts"],"names":[],"mappings":";;;AAAA,mCAAqC;AASrC,MAAa,qBAAsB,SAAQ,qBAAY;IAGnD,YAAY,YAAiC;QACzC,KAAK,EAAE,CAAA;QAHH;;;;;WAAiC;QAIrC,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;IACpC,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,EACV,MAAM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M,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,MAAM,CAAA;QACjC,IACI,OAAO,CAAC,WAAW,EAAE;YACrB,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,EACjD,CAAC;YACC,MAAM,IAAI,KAAK,CACX,yDAAyD,CAC5D,CAAA;QACL,CAAC;QAED,OAAO,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC;YACjC,OAAO;YACP,OAAO,EAAE,IAAI,CAAC,YAAY,CAAC,OAAO;SACrC,CAAC,CAAA;IACN,CAAC;CACJ;AAlED,sDAkEC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KernelEIP1193Provider = void 0;
|
|
4
|
+
var KernelEIP1193Provider_js_1 = require("./KernelEIP1193Provider.js");
|
|
5
|
+
Object.defineProperty(exports, "KernelEIP1193Provider", { enumerable: true, get: function () { return KernelEIP1193Provider_js_1.KernelEIP1193Provider; } });
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../providers/index.ts"],"names":[],"mappings":";;;AAAA,uEAAkE;AAAzD,iIAAA,qBAAqB,OAAA"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { EventEmitter } from "events";
|
|
2
|
+
import {} from "@zerodev/sdk";
|
|
3
|
+
import {} from "viem";
|
|
4
|
+
export class KernelEIP1193Provider extends EventEmitter {
|
|
5
|
+
constructor(kernelClient) {
|
|
6
|
+
super();
|
|
7
|
+
Object.defineProperty(this, "kernelClient", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
configurable: true,
|
|
10
|
+
writable: true,
|
|
11
|
+
value: void 0
|
|
12
|
+
});
|
|
13
|
+
this.kernelClient = kernelClient;
|
|
14
|
+
}
|
|
15
|
+
async request({ method, params = [] }) {
|
|
16
|
+
switch (method) {
|
|
17
|
+
case "eth_requestAccounts":
|
|
18
|
+
return this.handleEthRequestAccounts();
|
|
19
|
+
case "eth_accounts":
|
|
20
|
+
return this.handleEthAccounts();
|
|
21
|
+
case "eth_sendTransaction":
|
|
22
|
+
return this.handleEthSendTransaction(params);
|
|
23
|
+
case "personal_sign":
|
|
24
|
+
return this.handlePersonalSign(params);
|
|
25
|
+
default:
|
|
26
|
+
return this.kernelClient.transport.request({ method, params });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async handleEthRequestAccounts() {
|
|
30
|
+
if (!this.kernelClient.account) {
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
return [this.kernelClient.account.address];
|
|
34
|
+
}
|
|
35
|
+
async handleEthAccounts() {
|
|
36
|
+
if (!this.kernelClient.account) {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
return [this.kernelClient.account.address];
|
|
40
|
+
}
|
|
41
|
+
async handleEthSendTransaction(params) {
|
|
42
|
+
const [tx] = params;
|
|
43
|
+
return this.kernelClient.sendTransaction(tx);
|
|
44
|
+
}
|
|
45
|
+
async handlePersonalSign(params) {
|
|
46
|
+
if (!this.kernelClient?.account) {
|
|
47
|
+
throw new Error("account not connected!");
|
|
48
|
+
}
|
|
49
|
+
const [message, address] = params;
|
|
50
|
+
if (address.toLowerCase() !==
|
|
51
|
+
this.kernelClient.account.address.toLowerCase()) {
|
|
52
|
+
throw new Error("cannot sign for address that is not the current account");
|
|
53
|
+
}
|
|
54
|
+
return this.kernelClient.signMessage({
|
|
55
|
+
message,
|
|
56
|
+
account: this.kernelClient.account
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=KernelEIP1193Provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KernelEIP1193Provider.js","sourceRoot":"","sources":["../../providers/KernelEIP1193Provider.ts"],"names":[],"mappings":"AAAA,OAAO,EA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e;QAClD,MAAM,CAAC,EAAE,CAAC,GAAG,MAAqC,CAAA;QAClD,OAAO,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,EAAE,CAAC,CAAA;IAChD,CAAC;IAEO,KAAK,CAAC,kBAAkB,CAC5B,MAAwB;QAExB,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,OAAO,EAAE,CAAC;YAC9B,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAA;QAC7C,CAAC;QACD,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,MAAM,CAAA;QACjC,IACI,OAAO,CAAC,WAAW,EAAE;YACrB,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,EACjD,CAAC;YACC,MAAM,IAAI,KAAK,CACX,yDAAyD,CAC5D,CAAA;QACL,CAAC;QAED,OAAO,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC;YACjC,OAAO;YACP,OAAO,EAAE,IAAI,CAAC,YAAY,CAAC,OAAO;SACrC,CAAC,CAAA;IACN,CAAC;CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../providers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { EventEmitter } from "events";
|
|
3
|
+
import { type KernelAccountClient } from "@zerodev/sdk";
|
|
4
|
+
import { type EIP1193Parameters, type EIP1193RequestFn } from "viem";
|
|
5
|
+
export declare class KernelEIP1193Provider extends EventEmitter {
|
|
6
|
+
private kernelClient;
|
|
7
|
+
constructor(kernelClient: KernelAccountClient);
|
|
8
|
+
request({ method, params }: EIP1193Parameters): ReturnType<EIP1193RequestFn>;
|
|
9
|
+
private handleEthRequestAccounts;
|
|
10
|
+
private handleEthAccounts;
|
|
11
|
+
private handleEthSendTransaction;
|
|
12
|
+
private handlePersonalSign;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=KernelEIP1193Provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KernelEIP1193Provider.d.ts","sourceRoot":"","sources":["../../providers/KernelEIP1193Provider.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AACrC,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,cAAc,CAAA;AACvD,OAAO,EACH,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EAGxB,MAAM,MAAM,CAAA;AAEb,qBAAa,qBAAsB,SAAQ,YAAY;IACnD,OAAO,CAAC,YAAY,CAAqB;gBAE7B,YAAY,EAAE,mBAAmB;IAKvC,OAAO,CAAC,EACV,MAAM,EACN,MAAW,EACd,EAAE,iBAAiB,GAAG,UAAU,CAAC,gBAAgB,CAAC;YAerC,wBAAwB;YAOxB,iBAAiB;YAOjB,wBAAwB;YAKxB,kBAAkB;CAqBnC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../providers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zerodev/sdk",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.7",
|
|
4
4
|
"author": "ZeroDev",
|
|
5
5
|
"main": "./_cjs/index.js",
|
|
6
6
|
"module": "./_esm/index.js",
|
|
@@ -82,6 +82,11 @@
|
|
|
82
82
|
"types": "./_types/clients/kernel.d.ts",
|
|
83
83
|
"import": "./_esm/clients/kernel.js",
|
|
84
84
|
"default": "./_cjs/clients/kernel.js"
|
|
85
|
+
},
|
|
86
|
+
"./providers": {
|
|
87
|
+
"types": "./_types/providers/index.d.ts",
|
|
88
|
+
"import": "./_esm/providers/index.js",
|
|
89
|
+
"default": "./_cjs/provider/index.js"
|
|
85
90
|
}
|
|
86
91
|
},
|
|
87
92
|
"peerDependencies": {
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { EventEmitter } from "events"
|
|
2
|
+
import { type KernelAccountClient } from "@zerodev/sdk"
|
|
3
|
+
import {
|
|
4
|
+
type EIP1193Parameters,
|
|
5
|
+
type EIP1193RequestFn,
|
|
6
|
+
type Hash,
|
|
7
|
+
type SendTransactionParameters
|
|
8
|
+
} from "viem"
|
|
9
|
+
|
|
10
|
+
export class KernelEIP1193Provider extends EventEmitter {
|
|
11
|
+
private kernelClient: KernelAccountClient
|
|
12
|
+
|
|
13
|
+
constructor(kernelClient: KernelAccountClient) {
|
|
14
|
+
super()
|
|
15
|
+
this.kernelClient = kernelClient
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async request({
|
|
19
|
+
method,
|
|
20
|
+
params = []
|
|
21
|
+
}: EIP1193Parameters): ReturnType<EIP1193RequestFn> {
|
|
22
|
+
switch (method) {
|
|
23
|
+
case "eth_requestAccounts":
|
|
24
|
+
return this.handleEthRequestAccounts()
|
|
25
|
+
case "eth_accounts":
|
|
26
|
+
return this.handleEthAccounts()
|
|
27
|
+
case "eth_sendTransaction":
|
|
28
|
+
return this.handleEthSendTransaction(params)
|
|
29
|
+
case "personal_sign":
|
|
30
|
+
return this.handlePersonalSign(params as [string, string])
|
|
31
|
+
default:
|
|
32
|
+
return this.kernelClient.transport.request({ method, params })
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
private async handleEthRequestAccounts(): Promise<string[]> {
|
|
37
|
+
if (!this.kernelClient.account) {
|
|
38
|
+
return []
|
|
39
|
+
}
|
|
40
|
+
return [this.kernelClient.account.address]
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private async handleEthAccounts(): Promise<string[]> {
|
|
44
|
+
if (!this.kernelClient.account) {
|
|
45
|
+
return []
|
|
46
|
+
}
|
|
47
|
+
return [this.kernelClient.account.address]
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private async handleEthSendTransaction(params: unknown): Promise<Hash> {
|
|
51
|
+
const [tx] = params as [SendTransactionParameters]
|
|
52
|
+
return this.kernelClient.sendTransaction(tx)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
private async handlePersonalSign(
|
|
56
|
+
params: [string, string]
|
|
57
|
+
): Promise<string> {
|
|
58
|
+
if (!this.kernelClient?.account) {
|
|
59
|
+
throw new Error("account not connected!")
|
|
60
|
+
}
|
|
61
|
+
const [message, address] = params
|
|
62
|
+
if (
|
|
63
|
+
address.toLowerCase() !==
|
|
64
|
+
this.kernelClient.account.address.toLowerCase()
|
|
65
|
+
) {
|
|
66
|
+
throw new Error(
|
|
67
|
+
"cannot sign for address that is not the current account"
|
|
68
|
+
)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return this.kernelClient.signMessage({
|
|
72
|
+
message,
|
|
73
|
+
account: this.kernelClient.account
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { KernelEIP1193Provider } from "./KernelEIP1193Provider.js"
|