@getpara/ethers-v5-integration 1.4.2 → 1.4.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/dist/cjs/index.js +114 -1
- package/dist/cjs/index.js.br +0 -0
- package/dist/cjs/index.js.gz +0 -0
- package/dist/esm/index.js +88 -1
- package/dist/esm/index.js.br +0 -0
- package/dist/esm/index.js.gz +0 -0
- package/package.json +3 -3
package/dist/cjs/index.js
CHANGED
|
@@ -1 +1,114 @@
|
|
|
1
|
-
var
|
|
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
|
+
|
|
19
|
+
// src/index.ts
|
|
20
|
+
var src_exports = {};
|
|
21
|
+
__export(src_exports, {
|
|
22
|
+
ParaEthersV5Signer: () => ParaEthersV5Signer
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(src_exports);
|
|
25
|
+
|
|
26
|
+
// src/ethersSigner.ts
|
|
27
|
+
var import_ethers = require("ethers");
|
|
28
|
+
var import_hash = require("@ethersproject/hash");
|
|
29
|
+
var import_core_sdk = require("@getpara/core-sdk");
|
|
30
|
+
var import_utils = require("ethers/lib/utils");
|
|
31
|
+
var ParaEthersV5Signer = class _ParaEthersV5Signer extends import_ethers.ethers.Signer {
|
|
32
|
+
constructor(para, provider, walletId) {
|
|
33
|
+
super();
|
|
34
|
+
this.currentWalletId = para.findWalletId(walletId, { type: ["EVM"] });
|
|
35
|
+
this.para = para;
|
|
36
|
+
(0, import_utils.defineReadOnly)(this, "provider", provider);
|
|
37
|
+
}
|
|
38
|
+
setCurrentWalletId(walletId) {
|
|
39
|
+
if (!this.para.wallets[walletId]) {
|
|
40
|
+
throw new Error(`no wallet exists with id ${walletId}`);
|
|
41
|
+
}
|
|
42
|
+
this.currentWalletId = walletId;
|
|
43
|
+
}
|
|
44
|
+
getCurrentWalletId() {
|
|
45
|
+
const id = this.currentWalletId;
|
|
46
|
+
if (!id) {
|
|
47
|
+
throw new Error(`no wallet available`);
|
|
48
|
+
}
|
|
49
|
+
if (!this.para.wallets[id]) {
|
|
50
|
+
throw new Error(`no wallet exists with id ${id}`);
|
|
51
|
+
}
|
|
52
|
+
return id;
|
|
53
|
+
}
|
|
54
|
+
async getAddress() {
|
|
55
|
+
const walletId = this.getCurrentWalletId();
|
|
56
|
+
if (!walletId) {
|
|
57
|
+
throw new Error("no wallet available");
|
|
58
|
+
}
|
|
59
|
+
return this.para.wallets[walletId].address;
|
|
60
|
+
}
|
|
61
|
+
connect(provider) {
|
|
62
|
+
return new _ParaEthersV5Signer(this.para, provider, this.currentWalletId);
|
|
63
|
+
}
|
|
64
|
+
async signMessage(message) {
|
|
65
|
+
const hashedMessage = import_ethers.ethers.utils.hashMessage(message);
|
|
66
|
+
const base64HashedMessage = (0, import_core_sdk.hexStringToBase64)(hashedMessage);
|
|
67
|
+
const res = await this.para.signMessage({ walletId: this.getCurrentWalletId(), messageBase64: base64HashedMessage });
|
|
68
|
+
const signature = res.signature;
|
|
69
|
+
return `0x${signature}`;
|
|
70
|
+
}
|
|
71
|
+
async signTransaction(tx) {
|
|
72
|
+
return (0, import_utils.resolveProperties)(tx).then(async (tx2) => {
|
|
73
|
+
if (tx2.from != null) {
|
|
74
|
+
if ((await this.getAddress()).toLowerCase() !== import_ethers.ethers.utils.getAddress(tx2.from).toLowerCase()) {
|
|
75
|
+
throw new Error("transaction from address mismatch");
|
|
76
|
+
}
|
|
77
|
+
delete tx2.from;
|
|
78
|
+
}
|
|
79
|
+
let txObj = tx2;
|
|
80
|
+
txObj.r = "0x0";
|
|
81
|
+
txObj.s = "0x0";
|
|
82
|
+
txObj.v = 0;
|
|
83
|
+
const serializedTx = (0, import_utils.serializeTransaction)(txObj);
|
|
84
|
+
const message = (0, import_core_sdk.hexStringToBase64)((0, import_utils.keccak256)(serializedTx));
|
|
85
|
+
const signature = await this.signMessage(message);
|
|
86
|
+
return (0, import_utils.serializeTransaction)(txObj, signature);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
async signTypedData(domain, types, value) {
|
|
90
|
+
const populated = await import_hash._TypedDataEncoder.resolveNames(domain, types, value, async (name) => {
|
|
91
|
+
if (!this.provider) {
|
|
92
|
+
throw new Error("cannot resolve ENS names without a provider");
|
|
93
|
+
}
|
|
94
|
+
const address = await this.provider.resolveName(name);
|
|
95
|
+
if (!address) {
|
|
96
|
+
throw new Error("unconfigured ENS name");
|
|
97
|
+
}
|
|
98
|
+
return address;
|
|
99
|
+
});
|
|
100
|
+
const res = await this.para.signMessage({
|
|
101
|
+
walletId: this.getCurrentWalletId(),
|
|
102
|
+
messageBase64: (0, import_core_sdk.hexStringToBase64)(import_hash._TypedDataEncoder.hash(populated.domain, types, populated.value))
|
|
103
|
+
});
|
|
104
|
+
const signature = res.signature;
|
|
105
|
+
return `0x${signature}`;
|
|
106
|
+
}
|
|
107
|
+
async _signTypedData(domain, types, value) {
|
|
108
|
+
return this.signTypedData(domain, types, value);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
112
|
+
0 && (module.exports = {
|
|
113
|
+
ParaEthersV5Signer
|
|
114
|
+
});
|
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 +1,88 @@
|
|
|
1
|
-
|
|
1
|
+
// src/ethersSigner.ts
|
|
2
|
+
import { ethers } from "ethers";
|
|
3
|
+
import { _TypedDataEncoder } from "@ethersproject/hash";
|
|
4
|
+
import { hexStringToBase64 } from "@getpara/core-sdk";
|
|
5
|
+
import { defineReadOnly, keccak256, resolveProperties, serializeTransaction } from "ethers/lib/utils";
|
|
6
|
+
var ParaEthersV5Signer = class _ParaEthersV5Signer extends ethers.Signer {
|
|
7
|
+
constructor(para, provider, walletId) {
|
|
8
|
+
super();
|
|
9
|
+
this.currentWalletId = para.findWalletId(walletId, { type: ["EVM"] });
|
|
10
|
+
this.para = para;
|
|
11
|
+
defineReadOnly(this, "provider", provider);
|
|
12
|
+
}
|
|
13
|
+
setCurrentWalletId(walletId) {
|
|
14
|
+
if (!this.para.wallets[walletId]) {
|
|
15
|
+
throw new Error(`no wallet exists with id ${walletId}`);
|
|
16
|
+
}
|
|
17
|
+
this.currentWalletId = walletId;
|
|
18
|
+
}
|
|
19
|
+
getCurrentWalletId() {
|
|
20
|
+
const id = this.currentWalletId;
|
|
21
|
+
if (!id) {
|
|
22
|
+
throw new Error(`no wallet available`);
|
|
23
|
+
}
|
|
24
|
+
if (!this.para.wallets[id]) {
|
|
25
|
+
throw new Error(`no wallet exists with id ${id}`);
|
|
26
|
+
}
|
|
27
|
+
return id;
|
|
28
|
+
}
|
|
29
|
+
async getAddress() {
|
|
30
|
+
const walletId = this.getCurrentWalletId();
|
|
31
|
+
if (!walletId) {
|
|
32
|
+
throw new Error("no wallet available");
|
|
33
|
+
}
|
|
34
|
+
return this.para.wallets[walletId].address;
|
|
35
|
+
}
|
|
36
|
+
connect(provider) {
|
|
37
|
+
return new _ParaEthersV5Signer(this.para, provider, this.currentWalletId);
|
|
38
|
+
}
|
|
39
|
+
async signMessage(message) {
|
|
40
|
+
const hashedMessage = ethers.utils.hashMessage(message);
|
|
41
|
+
const base64HashedMessage = hexStringToBase64(hashedMessage);
|
|
42
|
+
const res = await this.para.signMessage({ walletId: this.getCurrentWalletId(), messageBase64: base64HashedMessage });
|
|
43
|
+
const signature = res.signature;
|
|
44
|
+
return `0x${signature}`;
|
|
45
|
+
}
|
|
46
|
+
async signTransaction(tx) {
|
|
47
|
+
return resolveProperties(tx).then(async (tx2) => {
|
|
48
|
+
if (tx2.from != null) {
|
|
49
|
+
if ((await this.getAddress()).toLowerCase() !== ethers.utils.getAddress(tx2.from).toLowerCase()) {
|
|
50
|
+
throw new Error("transaction from address mismatch");
|
|
51
|
+
}
|
|
52
|
+
delete tx2.from;
|
|
53
|
+
}
|
|
54
|
+
let txObj = tx2;
|
|
55
|
+
txObj.r = "0x0";
|
|
56
|
+
txObj.s = "0x0";
|
|
57
|
+
txObj.v = 0;
|
|
58
|
+
const serializedTx = serializeTransaction(txObj);
|
|
59
|
+
const message = hexStringToBase64(keccak256(serializedTx));
|
|
60
|
+
const signature = await this.signMessage(message);
|
|
61
|
+
return serializeTransaction(txObj, signature);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
async signTypedData(domain, types, value) {
|
|
65
|
+
const populated = await _TypedDataEncoder.resolveNames(domain, types, value, async (name) => {
|
|
66
|
+
if (!this.provider) {
|
|
67
|
+
throw new Error("cannot resolve ENS names without a provider");
|
|
68
|
+
}
|
|
69
|
+
const address = await this.provider.resolveName(name);
|
|
70
|
+
if (!address) {
|
|
71
|
+
throw new Error("unconfigured ENS name");
|
|
72
|
+
}
|
|
73
|
+
return address;
|
|
74
|
+
});
|
|
75
|
+
const res = await this.para.signMessage({
|
|
76
|
+
walletId: this.getCurrentWalletId(),
|
|
77
|
+
messageBase64: hexStringToBase64(_TypedDataEncoder.hash(populated.domain, types, populated.value))
|
|
78
|
+
});
|
|
79
|
+
const signature = res.signature;
|
|
80
|
+
return `0x${signature}`;
|
|
81
|
+
}
|
|
82
|
+
async _signTypedData(domain, types, value) {
|
|
83
|
+
return this.signTypedData(domain, types, value);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
export {
|
|
87
|
+
ParaEthersV5Signer
|
|
88
|
+
};
|
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.4.
|
|
3
|
+
"version": "1.4.4",
|
|
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.4.
|
|
10
|
+
"@getpara/core-sdk": "1.4.4",
|
|
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": "9a4086c4b352fff2143d3b931d288c5ebaf127fb"
|
|
35
35
|
}
|