@getpara/ethers-v5-integration 2.0.0-dev.1 → 2.0.0-dev.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/dist/cjs/ethersSigner.js +140 -0
- package/dist/cjs/index.js +3 -126
- package/dist/cjs/package.json +3 -0
- package/dist/esm/ethersSigner.js +117 -0
- package/dist/esm/index.js +1 -119
- package/dist/esm/package.json +4 -0
- package/package.json +26 -23
- package/dist/cjs/index.js.br +0 -0
- package/dist/cjs/index.js.gz +0 -0
- package/dist/esm/index.js.br +0 -0
- package/dist/esm/index.js.gz +0 -0
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var __async = (__this, __arguments, generator) => {
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
var fulfilled = (value) => {
|
|
21
|
+
try {
|
|
22
|
+
step(generator.next(value));
|
|
23
|
+
} catch (e) {
|
|
24
|
+
reject(e);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var rejected = (value) => {
|
|
28
|
+
try {
|
|
29
|
+
step(generator.throw(value));
|
|
30
|
+
} catch (e) {
|
|
31
|
+
reject(e);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
35
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
var ethersSigner_exports = {};
|
|
39
|
+
__export(ethersSigner_exports, {
|
|
40
|
+
ParaEthersV5Signer: () => ParaEthersV5Signer
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(ethersSigner_exports);
|
|
43
|
+
var import_ethers = require("ethers");
|
|
44
|
+
var import_hash = require("@ethersproject/hash");
|
|
45
|
+
var import_core_sdk = require("@getpara/core-sdk");
|
|
46
|
+
var import_utils = require("ethers/lib/utils");
|
|
47
|
+
class ParaEthersV5Signer extends import_ethers.ethers.Signer {
|
|
48
|
+
constructor(para, provider, walletId) {
|
|
49
|
+
super();
|
|
50
|
+
this.currentWalletId = para.findWalletId(walletId, { type: ["EVM"] });
|
|
51
|
+
this.para = para;
|
|
52
|
+
(0, import_utils.defineReadOnly)(this, "provider", provider);
|
|
53
|
+
}
|
|
54
|
+
setCurrentWalletId(walletId) {
|
|
55
|
+
if (!this.para.wallets[walletId]) {
|
|
56
|
+
throw new Error(`no wallet exists with id ${walletId}`);
|
|
57
|
+
}
|
|
58
|
+
this.currentWalletId = walletId;
|
|
59
|
+
}
|
|
60
|
+
getCurrentWalletId() {
|
|
61
|
+
const id = this.currentWalletId;
|
|
62
|
+
if (!id) {
|
|
63
|
+
throw new Error(`no wallet available`);
|
|
64
|
+
}
|
|
65
|
+
if (!this.para.wallets[id]) {
|
|
66
|
+
throw new Error(`no wallet exists with id ${id}`);
|
|
67
|
+
}
|
|
68
|
+
return id;
|
|
69
|
+
}
|
|
70
|
+
getAddress() {
|
|
71
|
+
return __async(this, null, function* () {
|
|
72
|
+
const walletId = this.getCurrentWalletId();
|
|
73
|
+
if (!walletId) {
|
|
74
|
+
throw new Error("no wallet available");
|
|
75
|
+
}
|
|
76
|
+
return this.para.wallets[walletId].address;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
connect(provider) {
|
|
80
|
+
return new ParaEthersV5Signer(this.para, provider, this.currentWalletId);
|
|
81
|
+
}
|
|
82
|
+
signMessage(message) {
|
|
83
|
+
return __async(this, null, function* () {
|
|
84
|
+
const hashedMessage = import_ethers.ethers.utils.hashMessage(message);
|
|
85
|
+
const base64HashedMessage = (0, import_core_sdk.hexStringToBase64)(hashedMessage);
|
|
86
|
+
const res = yield this.para.signMessage({ walletId: this.getCurrentWalletId(), messageBase64: base64HashedMessage });
|
|
87
|
+
const signature = res.signature;
|
|
88
|
+
return `0x${signature}`;
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
signTransaction(tx) {
|
|
92
|
+
return __async(this, null, function* () {
|
|
93
|
+
return (0, import_utils.resolveProperties)(tx).then((tx2) => __async(this, null, function* () {
|
|
94
|
+
if (tx2.from != null) {
|
|
95
|
+
if ((yield this.getAddress()).toLowerCase() !== import_ethers.ethers.utils.getAddress(tx2.from).toLowerCase()) {
|
|
96
|
+
throw new Error("transaction from address mismatch");
|
|
97
|
+
}
|
|
98
|
+
delete tx2.from;
|
|
99
|
+
}
|
|
100
|
+
let txObj = tx2;
|
|
101
|
+
txObj.r = "0x0";
|
|
102
|
+
txObj.s = "0x0";
|
|
103
|
+
txObj.v = 0;
|
|
104
|
+
const serializedTx = (0, import_utils.serializeTransaction)(txObj);
|
|
105
|
+
const message = (0, import_core_sdk.hexStringToBase64)((0, import_utils.keccak256)(serializedTx));
|
|
106
|
+
const signature = yield this.signMessage(message);
|
|
107
|
+
return (0, import_utils.serializeTransaction)(txObj, signature);
|
|
108
|
+
}));
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
signTypedData(domain, types, value) {
|
|
112
|
+
return __async(this, null, function* () {
|
|
113
|
+
const populated = yield import_hash._TypedDataEncoder.resolveNames(domain, types, value, (name) => __async(this, null, function* () {
|
|
114
|
+
if (!this.provider) {
|
|
115
|
+
throw new Error("cannot resolve ENS names without a provider");
|
|
116
|
+
}
|
|
117
|
+
const address = yield this.provider.resolveName(name);
|
|
118
|
+
if (!address) {
|
|
119
|
+
throw new Error("unconfigured ENS name");
|
|
120
|
+
}
|
|
121
|
+
return address;
|
|
122
|
+
}));
|
|
123
|
+
const res = yield this.para.signMessage({
|
|
124
|
+
walletId: this.getCurrentWalletId(),
|
|
125
|
+
messageBase64: (0, import_core_sdk.hexStringToBase64)(import_hash._TypedDataEncoder.hash(populated.domain, types, populated.value))
|
|
126
|
+
});
|
|
127
|
+
const signature = res.signature;
|
|
128
|
+
return `0x${signature}`;
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
_signTypedData(domain, types, value) {
|
|
132
|
+
return __async(this, null, function* () {
|
|
133
|
+
return this.signTypedData(domain, types, value);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
138
|
+
0 && (module.exports = {
|
|
139
|
+
ParaEthersV5Signer
|
|
140
|
+
});
|
package/dist/cjs/index.js
CHANGED
|
@@ -2,10 +2,6 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
5
|
var __copyProps = (to, from, except, desc) => {
|
|
10
6
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
7
|
for (let key of __getOwnPropNames(from))
|
|
@@ -14,131 +10,12 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
14
10
|
}
|
|
15
11
|
return to;
|
|
16
12
|
};
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
17
14
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var __async = (__this, __arguments, generator) => {
|
|
19
|
-
return new Promise((resolve, reject) => {
|
|
20
|
-
var fulfilled = (value) => {
|
|
21
|
-
try {
|
|
22
|
-
step(generator.next(value));
|
|
23
|
-
} catch (e) {
|
|
24
|
-
reject(e);
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
var rejected = (value) => {
|
|
28
|
-
try {
|
|
29
|
-
step(generator.throw(value));
|
|
30
|
-
} catch (e) {
|
|
31
|
-
reject(e);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
35
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
// src/index.ts
|
|
40
15
|
var src_exports = {};
|
|
41
|
-
__export(src_exports, {
|
|
42
|
-
ParaEthersV5Signer: () => ParaEthersV5Signer
|
|
43
|
-
});
|
|
44
16
|
module.exports = __toCommonJS(src_exports);
|
|
45
|
-
|
|
46
|
-
// src/ethersSigner.ts
|
|
47
|
-
var import_ethers = require("ethers");
|
|
48
|
-
var import_hash = require("@ethersproject/hash");
|
|
49
|
-
var import_core_sdk = require("@getpara/core-sdk");
|
|
50
|
-
var import_utils = require("ethers/lib/utils");
|
|
51
|
-
var ParaEthersV5Signer = class _ParaEthersV5Signer extends import_ethers.ethers.Signer {
|
|
52
|
-
constructor(para, provider, walletId) {
|
|
53
|
-
super();
|
|
54
|
-
this.currentWalletId = para.findWalletId(walletId, { type: ["EVM"] });
|
|
55
|
-
this.para = para;
|
|
56
|
-
(0, import_utils.defineReadOnly)(this, "provider", provider);
|
|
57
|
-
}
|
|
58
|
-
setCurrentWalletId(walletId) {
|
|
59
|
-
if (!this.para.wallets[walletId]) {
|
|
60
|
-
throw new Error(`no wallet exists with id ${walletId}`);
|
|
61
|
-
}
|
|
62
|
-
this.currentWalletId = walletId;
|
|
63
|
-
}
|
|
64
|
-
getCurrentWalletId() {
|
|
65
|
-
const id = this.currentWalletId;
|
|
66
|
-
if (!id) {
|
|
67
|
-
throw new Error(`no wallet available`);
|
|
68
|
-
}
|
|
69
|
-
if (!this.para.wallets[id]) {
|
|
70
|
-
throw new Error(`no wallet exists with id ${id}`);
|
|
71
|
-
}
|
|
72
|
-
return id;
|
|
73
|
-
}
|
|
74
|
-
getAddress() {
|
|
75
|
-
return __async(this, null, function* () {
|
|
76
|
-
const walletId = this.getCurrentWalletId();
|
|
77
|
-
if (!walletId) {
|
|
78
|
-
throw new Error("no wallet available");
|
|
79
|
-
}
|
|
80
|
-
return this.para.wallets[walletId].address;
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
connect(provider) {
|
|
84
|
-
return new _ParaEthersV5Signer(this.para, provider, this.currentWalletId);
|
|
85
|
-
}
|
|
86
|
-
signMessage(message) {
|
|
87
|
-
return __async(this, null, function* () {
|
|
88
|
-
const hashedMessage = import_ethers.ethers.utils.hashMessage(message);
|
|
89
|
-
const base64HashedMessage = (0, import_core_sdk.hexStringToBase64)(hashedMessage);
|
|
90
|
-
const res = yield this.para.signMessage({ walletId: this.getCurrentWalletId(), messageBase64: base64HashedMessage });
|
|
91
|
-
const signature = res.signature;
|
|
92
|
-
return `0x${signature}`;
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
signTransaction(tx) {
|
|
96
|
-
return __async(this, null, function* () {
|
|
97
|
-
return (0, import_utils.resolveProperties)(tx).then((tx2) => __async(this, null, function* () {
|
|
98
|
-
if (tx2.from != null) {
|
|
99
|
-
if ((yield this.getAddress()).toLowerCase() !== import_ethers.ethers.utils.getAddress(tx2.from).toLowerCase()) {
|
|
100
|
-
throw new Error("transaction from address mismatch");
|
|
101
|
-
}
|
|
102
|
-
delete tx2.from;
|
|
103
|
-
}
|
|
104
|
-
let txObj = tx2;
|
|
105
|
-
txObj.r = "0x0";
|
|
106
|
-
txObj.s = "0x0";
|
|
107
|
-
txObj.v = 0;
|
|
108
|
-
const serializedTx = (0, import_utils.serializeTransaction)(txObj);
|
|
109
|
-
const message = (0, import_core_sdk.hexStringToBase64)((0, import_utils.keccak256)(serializedTx));
|
|
110
|
-
const signature = yield this.signMessage(message);
|
|
111
|
-
return (0, import_utils.serializeTransaction)(txObj, signature);
|
|
112
|
-
}));
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
signTypedData(domain, types, value) {
|
|
116
|
-
return __async(this, null, function* () {
|
|
117
|
-
const populated = yield import_hash._TypedDataEncoder.resolveNames(domain, types, value, (name) => __async(this, null, function* () {
|
|
118
|
-
if (!this.provider) {
|
|
119
|
-
throw new Error("cannot resolve ENS names without a provider");
|
|
120
|
-
}
|
|
121
|
-
const address = yield this.provider.resolveName(name);
|
|
122
|
-
if (!address) {
|
|
123
|
-
throw new Error("unconfigured ENS name");
|
|
124
|
-
}
|
|
125
|
-
return address;
|
|
126
|
-
}));
|
|
127
|
-
const res = yield this.para.signMessage({
|
|
128
|
-
walletId: this.getCurrentWalletId(),
|
|
129
|
-
messageBase64: (0, import_core_sdk.hexStringToBase64)(import_hash._TypedDataEncoder.hash(populated.domain, types, populated.value))
|
|
130
|
-
});
|
|
131
|
-
const signature = res.signature;
|
|
132
|
-
return `0x${signature}`;
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
_signTypedData(domain, types, value) {
|
|
136
|
-
return __async(this, null, function* () {
|
|
137
|
-
return this.signTypedData(domain, types, value);
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
};
|
|
17
|
+
__reExport(src_exports, require("./ethersSigner.js"), module.exports);
|
|
141
18
|
// Annotate the CommonJS export names for ESM import in node:
|
|
142
19
|
0 && (module.exports = {
|
|
143
|
-
|
|
20
|
+
...require("./ethersSigner.js")
|
|
144
21
|
});
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
import { ethers } from "ethers";
|
|
22
|
+
import { _TypedDataEncoder } from "@ethersproject/hash";
|
|
23
|
+
import { hexStringToBase64 } from "@getpara/core-sdk";
|
|
24
|
+
import { defineReadOnly, keccak256, resolveProperties, serializeTransaction } from "ethers/lib/utils";
|
|
25
|
+
class ParaEthersV5Signer extends ethers.Signer {
|
|
26
|
+
constructor(para, provider, walletId) {
|
|
27
|
+
super();
|
|
28
|
+
this.currentWalletId = para.findWalletId(walletId, { type: ["EVM"] });
|
|
29
|
+
this.para = para;
|
|
30
|
+
defineReadOnly(this, "provider", provider);
|
|
31
|
+
}
|
|
32
|
+
setCurrentWalletId(walletId) {
|
|
33
|
+
if (!this.para.wallets[walletId]) {
|
|
34
|
+
throw new Error(`no wallet exists with id ${walletId}`);
|
|
35
|
+
}
|
|
36
|
+
this.currentWalletId = walletId;
|
|
37
|
+
}
|
|
38
|
+
getCurrentWalletId() {
|
|
39
|
+
const id = this.currentWalletId;
|
|
40
|
+
if (!id) {
|
|
41
|
+
throw new Error(`no wallet available`);
|
|
42
|
+
}
|
|
43
|
+
if (!this.para.wallets[id]) {
|
|
44
|
+
throw new Error(`no wallet exists with id ${id}`);
|
|
45
|
+
}
|
|
46
|
+
return id;
|
|
47
|
+
}
|
|
48
|
+
getAddress() {
|
|
49
|
+
return __async(this, null, function* () {
|
|
50
|
+
const walletId = this.getCurrentWalletId();
|
|
51
|
+
if (!walletId) {
|
|
52
|
+
throw new Error("no wallet available");
|
|
53
|
+
}
|
|
54
|
+
return this.para.wallets[walletId].address;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
connect(provider) {
|
|
58
|
+
return new ParaEthersV5Signer(this.para, provider, this.currentWalletId);
|
|
59
|
+
}
|
|
60
|
+
signMessage(message) {
|
|
61
|
+
return __async(this, null, function* () {
|
|
62
|
+
const hashedMessage = ethers.utils.hashMessage(message);
|
|
63
|
+
const base64HashedMessage = hexStringToBase64(hashedMessage);
|
|
64
|
+
const res = yield this.para.signMessage({ walletId: this.getCurrentWalletId(), messageBase64: base64HashedMessage });
|
|
65
|
+
const signature = res.signature;
|
|
66
|
+
return `0x${signature}`;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
signTransaction(tx) {
|
|
70
|
+
return __async(this, null, function* () {
|
|
71
|
+
return resolveProperties(tx).then((tx2) => __async(this, null, function* () {
|
|
72
|
+
if (tx2.from != null) {
|
|
73
|
+
if ((yield this.getAddress()).toLowerCase() !== ethers.utils.getAddress(tx2.from).toLowerCase()) {
|
|
74
|
+
throw new Error("transaction from address mismatch");
|
|
75
|
+
}
|
|
76
|
+
delete tx2.from;
|
|
77
|
+
}
|
|
78
|
+
let txObj = tx2;
|
|
79
|
+
txObj.r = "0x0";
|
|
80
|
+
txObj.s = "0x0";
|
|
81
|
+
txObj.v = 0;
|
|
82
|
+
const serializedTx = serializeTransaction(txObj);
|
|
83
|
+
const message = hexStringToBase64(keccak256(serializedTx));
|
|
84
|
+
const signature = yield this.signMessage(message);
|
|
85
|
+
return serializeTransaction(txObj, signature);
|
|
86
|
+
}));
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
signTypedData(domain, types, value) {
|
|
90
|
+
return __async(this, null, function* () {
|
|
91
|
+
const populated = yield _TypedDataEncoder.resolveNames(domain, types, value, (name) => __async(this, null, function* () {
|
|
92
|
+
if (!this.provider) {
|
|
93
|
+
throw new Error("cannot resolve ENS names without a provider");
|
|
94
|
+
}
|
|
95
|
+
const address = yield this.provider.resolveName(name);
|
|
96
|
+
if (!address) {
|
|
97
|
+
throw new Error("unconfigured ENS name");
|
|
98
|
+
}
|
|
99
|
+
return address;
|
|
100
|
+
}));
|
|
101
|
+
const res = yield this.para.signMessage({
|
|
102
|
+
walletId: this.getCurrentWalletId(),
|
|
103
|
+
messageBase64: hexStringToBase64(_TypedDataEncoder.hash(populated.domain, types, populated.value))
|
|
104
|
+
});
|
|
105
|
+
const signature = res.signature;
|
|
106
|
+
return `0x${signature}`;
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
_signTypedData(domain, types, value) {
|
|
110
|
+
return __async(this, null, function* () {
|
|
111
|
+
return this.signTypedData(domain, types, value);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
export {
|
|
116
|
+
ParaEthersV5Signer
|
|
117
|
+
};
|
package/dist/esm/index.js
CHANGED
|
@@ -1,119 +1 @@
|
|
|
1
|
-
|
|
2
|
-
return new Promise((resolve, reject) => {
|
|
3
|
-
var fulfilled = (value) => {
|
|
4
|
-
try {
|
|
5
|
-
step(generator.next(value));
|
|
6
|
-
} catch (e) {
|
|
7
|
-
reject(e);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
var rejected = (value) => {
|
|
11
|
-
try {
|
|
12
|
-
step(generator.throw(value));
|
|
13
|
-
} catch (e) {
|
|
14
|
-
reject(e);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
// src/ethersSigner.ts
|
|
23
|
-
import { ethers } from "ethers";
|
|
24
|
-
import { _TypedDataEncoder } from "@ethersproject/hash";
|
|
25
|
-
import { hexStringToBase64 } from "@getpara/core-sdk";
|
|
26
|
-
import { defineReadOnly, keccak256, resolveProperties, serializeTransaction } from "ethers/lib/utils";
|
|
27
|
-
var ParaEthersV5Signer = class _ParaEthersV5Signer extends ethers.Signer {
|
|
28
|
-
constructor(para, provider, walletId) {
|
|
29
|
-
super();
|
|
30
|
-
this.currentWalletId = para.findWalletId(walletId, { type: ["EVM"] });
|
|
31
|
-
this.para = para;
|
|
32
|
-
defineReadOnly(this, "provider", provider);
|
|
33
|
-
}
|
|
34
|
-
setCurrentWalletId(walletId) {
|
|
35
|
-
if (!this.para.wallets[walletId]) {
|
|
36
|
-
throw new Error(`no wallet exists with id ${walletId}`);
|
|
37
|
-
}
|
|
38
|
-
this.currentWalletId = walletId;
|
|
39
|
-
}
|
|
40
|
-
getCurrentWalletId() {
|
|
41
|
-
const id = this.currentWalletId;
|
|
42
|
-
if (!id) {
|
|
43
|
-
throw new Error(`no wallet available`);
|
|
44
|
-
}
|
|
45
|
-
if (!this.para.wallets[id]) {
|
|
46
|
-
throw new Error(`no wallet exists with id ${id}`);
|
|
47
|
-
}
|
|
48
|
-
return id;
|
|
49
|
-
}
|
|
50
|
-
getAddress() {
|
|
51
|
-
return __async(this, null, function* () {
|
|
52
|
-
const walletId = this.getCurrentWalletId();
|
|
53
|
-
if (!walletId) {
|
|
54
|
-
throw new Error("no wallet available");
|
|
55
|
-
}
|
|
56
|
-
return this.para.wallets[walletId].address;
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
connect(provider) {
|
|
60
|
-
return new _ParaEthersV5Signer(this.para, provider, this.currentWalletId);
|
|
61
|
-
}
|
|
62
|
-
signMessage(message) {
|
|
63
|
-
return __async(this, null, function* () {
|
|
64
|
-
const hashedMessage = ethers.utils.hashMessage(message);
|
|
65
|
-
const base64HashedMessage = hexStringToBase64(hashedMessage);
|
|
66
|
-
const res = yield this.para.signMessage({ walletId: this.getCurrentWalletId(), messageBase64: base64HashedMessage });
|
|
67
|
-
const signature = res.signature;
|
|
68
|
-
return `0x${signature}`;
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
signTransaction(tx) {
|
|
72
|
-
return __async(this, null, function* () {
|
|
73
|
-
return resolveProperties(tx).then((tx2) => __async(this, null, function* () {
|
|
74
|
-
if (tx2.from != null) {
|
|
75
|
-
if ((yield this.getAddress()).toLowerCase() !== ethers.utils.getAddress(tx2.from).toLowerCase()) {
|
|
76
|
-
throw new Error("transaction from address mismatch");
|
|
77
|
-
}
|
|
78
|
-
delete tx2.from;
|
|
79
|
-
}
|
|
80
|
-
let txObj = tx2;
|
|
81
|
-
txObj.r = "0x0";
|
|
82
|
-
txObj.s = "0x0";
|
|
83
|
-
txObj.v = 0;
|
|
84
|
-
const serializedTx = serializeTransaction(txObj);
|
|
85
|
-
const message = hexStringToBase64(keccak256(serializedTx));
|
|
86
|
-
const signature = yield this.signMessage(message);
|
|
87
|
-
return serializeTransaction(txObj, signature);
|
|
88
|
-
}));
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
signTypedData(domain, types, value) {
|
|
92
|
-
return __async(this, null, function* () {
|
|
93
|
-
const populated = yield _TypedDataEncoder.resolveNames(domain, types, value, (name) => __async(this, null, function* () {
|
|
94
|
-
if (!this.provider) {
|
|
95
|
-
throw new Error("cannot resolve ENS names without a provider");
|
|
96
|
-
}
|
|
97
|
-
const address = yield this.provider.resolveName(name);
|
|
98
|
-
if (!address) {
|
|
99
|
-
throw new Error("unconfigured ENS name");
|
|
100
|
-
}
|
|
101
|
-
return address;
|
|
102
|
-
}));
|
|
103
|
-
const res = yield this.para.signMessage({
|
|
104
|
-
walletId: this.getCurrentWalletId(),
|
|
105
|
-
messageBase64: hexStringToBase64(_TypedDataEncoder.hash(populated.domain, types, populated.value))
|
|
106
|
-
});
|
|
107
|
-
const signature = res.signature;
|
|
108
|
-
return `0x${signature}`;
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
_signTypedData(domain, types, value) {
|
|
112
|
-
return __async(this, null, function* () {
|
|
113
|
-
return this.signTypedData(domain, types, value);
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
export {
|
|
118
|
-
ParaEthersV5Signer
|
|
119
|
-
};
|
|
1
|
+
export * from "./ethersSigner.js";
|
package/package.json
CHANGED
|
@@ -1,35 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getpara/ethers-v5-integration",
|
|
3
|
-
"version": "2.0.0-dev.
|
|
4
|
-
"main": "dist/cjs/index.js",
|
|
5
|
-
"module": "dist/esm/index.js",
|
|
6
|
-
"types": "dist/types/index.d.ts",
|
|
7
|
-
"typings": "dist/types/index.d.ts",
|
|
8
|
-
"sideEffects": false,
|
|
3
|
+
"version": "2.0.0-dev.3",
|
|
9
4
|
"dependencies": {
|
|
10
|
-
"@getpara/core-sdk": "2.0.0-dev.
|
|
11
|
-
"ethers": "^5.7.2"
|
|
12
|
-
},
|
|
13
|
-
"scripts": {
|
|
14
|
-
"build": "rm -rf dist && node ./scripts/build.mjs && yarn build:types",
|
|
15
|
-
"old-build": "yarn build:cjs && yarn build:esm && yarn build:types",
|
|
16
|
-
"build:cjs": "rm -rf dist/cjs && tsc --module commonjs --outDir dist/cjs && printf '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
|
|
17
|
-
"build:esm": "rm -rf dist/esm && tsc --module es6 --outDir dist/esm && printf '{\"type\":\"module\",\"sideEffects\":false}' > dist/esm/package.json",
|
|
18
|
-
"build:types": "rm -rf dist/types && tsc --module es6 --declarationDir dist/types --emitDeclarationOnly --declaration"
|
|
5
|
+
"@getpara/core-sdk": "2.0.0-dev.3"
|
|
19
6
|
},
|
|
20
7
|
"devDependencies": {
|
|
21
|
-
"
|
|
8
|
+
"ethers": "^5.8.0",
|
|
9
|
+
"typescript": "^5.8.3"
|
|
22
10
|
},
|
|
23
|
-
"files": [
|
|
24
|
-
"dist",
|
|
25
|
-
"package.json"
|
|
26
|
-
],
|
|
27
11
|
"exports": {
|
|
28
12
|
".": {
|
|
13
|
+
"types": "./dist/types/index.d.ts",
|
|
29
14
|
"import": "./dist/esm/index.js",
|
|
30
|
-
"require": "./dist/cjs/index.js"
|
|
31
|
-
"types": "./dist/types/index.d.ts"
|
|
15
|
+
"require": "./dist/cjs/index.js"
|
|
32
16
|
}
|
|
33
17
|
},
|
|
34
|
-
"
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"package.json"
|
|
21
|
+
],
|
|
22
|
+
"gitHead": "ffe34f7d8df2dd3c2327ca1f35bcc9764e0a68a2",
|
|
23
|
+
"main": "dist/cjs/index.js",
|
|
24
|
+
"module": "dist/esm/index.js",
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"ethers": "5.x"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "rm -rf dist && node ./scripts/build.mjs && yarn build:types",
|
|
30
|
+
"build:cjs": "rm -rf dist/cjs && tsc --module commonjs --outDir dist/cjs && printf '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
|
|
31
|
+
"build:esm": "rm -rf dist/esm && tsc --module es6 --outDir dist/esm && printf '{\"type\":\"module\",\"sideEffects\":false}' > dist/esm/package.json",
|
|
32
|
+
"build:types": "rm -rf dist/types && tsc --module es6 --declarationDir dist/types --emitDeclarationOnly --declaration",
|
|
33
|
+
"old-build": "yarn build:cjs && yarn build:esm && yarn build:types"
|
|
34
|
+
},
|
|
35
|
+
"sideEffects": false,
|
|
36
|
+
"types": "dist/types/index.d.ts",
|
|
37
|
+
"typings": "dist/types/index.d.ts"
|
|
35
38
|
}
|
package/dist/cjs/index.js.br
DELETED
|
Binary file
|
package/dist/cjs/index.js.gz
DELETED
|
Binary file
|
package/dist/esm/index.js.br
DELETED
|
Binary file
|
package/dist/esm/index.js.gz
DELETED
|
Binary file
|