@getpara/ethers-v5-integration 1.5.0 → 1.6.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/dist/cjs/index.js +75 -45
- package/dist/cjs/index.js.br +0 -0
- package/dist/cjs/index.js.gz +0 -0
- package/dist/cjs/package.json +3 -0
- package/dist/esm/index.js +76 -45
- package/dist/esm/index.js.br +0 -0
- package/dist/esm/index.js.gz +0 -0
- package/dist/esm/package.json +4 -0
- package/package.json +3 -3
package/dist/cjs/index.js
CHANGED
|
@@ -15,6 +15,26 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
15
|
return to;
|
|
16
16
|
};
|
|
17
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
|
+
};
|
|
18
38
|
|
|
19
39
|
// src/index.ts
|
|
20
40
|
var src_exports = {};
|
|
@@ -51,61 +71,71 @@ var ParaEthersV5Signer = class _ParaEthersV5Signer extends import_ethers.ethers.
|
|
|
51
71
|
}
|
|
52
72
|
return id;
|
|
53
73
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
+
});
|
|
60
82
|
}
|
|
61
83
|
connect(provider) {
|
|
62
84
|
return new _ParaEthersV5Signer(this.para, provider, this.currentWalletId);
|
|
63
85
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
+
});
|
|
70
94
|
}
|
|
71
|
-
|
|
72
|
-
return (
|
|
73
|
-
|
|
74
|
-
if (
|
|
75
|
-
|
|
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;
|
|
76
103
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return (0, import_utils.serializeTransaction)(txObj, signature);
|
|
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
|
+
}));
|
|
87
113
|
});
|
|
88
114
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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}`;
|
|
103
133
|
});
|
|
104
|
-
const signature = res.signature;
|
|
105
|
-
return `0x${signature}`;
|
|
106
134
|
}
|
|
107
|
-
|
|
108
|
-
return this
|
|
135
|
+
_signTypedData(domain, types, value) {
|
|
136
|
+
return __async(this, null, function* () {
|
|
137
|
+
return this.signTypedData(domain, types, value);
|
|
138
|
+
});
|
|
109
139
|
}
|
|
110
140
|
};
|
|
111
141
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/cjs/index.js.br
CHANGED
|
Binary file
|
package/dist/cjs/index.js.gz
CHANGED
|
Binary file
|
package/dist/esm/index.js
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
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
|
+
|
|
1
22
|
// src/ethersSigner.ts
|
|
2
23
|
import { ethers } from "ethers";
|
|
3
24
|
import { _TypedDataEncoder } from "@ethersproject/hash";
|
|
@@ -26,61 +47,71 @@ var ParaEthersV5Signer = class _ParaEthersV5Signer extends ethers.Signer {
|
|
|
26
47
|
}
|
|
27
48
|
return id;
|
|
28
49
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
+
});
|
|
35
58
|
}
|
|
36
59
|
connect(provider) {
|
|
37
60
|
return new _ParaEthersV5Signer(this.para, provider, this.currentWalletId);
|
|
38
61
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
+
});
|
|
45
70
|
}
|
|
46
|
-
|
|
47
|
-
return
|
|
48
|
-
|
|
49
|
-
if (
|
|
50
|
-
|
|
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;
|
|
51
79
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return serializeTransaction(txObj, signature);
|
|
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
|
+
}));
|
|
62
89
|
});
|
|
63
90
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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}`;
|
|
78
109
|
});
|
|
79
|
-
const signature = res.signature;
|
|
80
|
-
return `0x${signature}`;
|
|
81
110
|
}
|
|
82
|
-
|
|
83
|
-
return this
|
|
111
|
+
_signTypedData(domain, types, value) {
|
|
112
|
+
return __async(this, null, function* () {
|
|
113
|
+
return this.signTypedData(domain, types, value);
|
|
114
|
+
});
|
|
84
115
|
}
|
|
85
116
|
};
|
|
86
117
|
export {
|
package/dist/esm/index.js.br
CHANGED
|
Binary file
|
package/dist/esm/index.js.gz
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getpara/ethers-v5-integration",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
7
7
|
"typings": "dist/types/index.d.ts",
|
|
8
8
|
"sideEffects": false,
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@getpara/core-sdk": "1.
|
|
10
|
+
"@getpara/core-sdk": "1.6.0",
|
|
11
11
|
"ethers": "^5.7.2"
|
|
12
12
|
},
|
|
13
13
|
"scripts": {
|
|
@@ -31,5 +31,5 @@
|
|
|
31
31
|
"types": "./dist/types/index.d.ts"
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "2dd6c8ea893d72d693804e5c5b0856d2ea6c3a7a"
|
|
35
35
|
}
|