@getpara/ethers-v6-integration 1.4.3 → 1.5.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 +128 -1
- package/dist/cjs/index.js.br +0 -0
- package/dist/cjs/index.js.gz +0 -0
- package/dist/esm/index.js +102 -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,128 @@
|
|
|
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
|
+
ParaEthersSigner: () => ParaEthersSigner
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(src_exports);
|
|
25
|
+
|
|
26
|
+
// src/ethersSigner.ts
|
|
27
|
+
var import_ethers = require("ethers");
|
|
28
|
+
var import_core_sdk = require("@getpara/core-sdk");
|
|
29
|
+
var ParaEthersSigner = class _ParaEthersSigner extends import_ethers.ethers.AbstractSigner {
|
|
30
|
+
/**
|
|
31
|
+
* Signs a message.
|
|
32
|
+
*
|
|
33
|
+
* @param para - the ParaCore instance
|
|
34
|
+
* @param provider - the ethers provider to use. If not present, will use the default ethers.Provider.
|
|
35
|
+
* @param walletId - optional wallet ID to use. If not present, will use the first wallet found.
|
|
36
|
+
* @param messageSigningTimeoutMs - optional timeout in milliseconds. If not present, defaults to 30 seconds.
|
|
37
|
+
**/
|
|
38
|
+
constructor(para, provider, walletId, messageSigningTimeoutMs) {
|
|
39
|
+
super(provider);
|
|
40
|
+
this.currentWalletId = para.findWalletId(walletId, { type: ["EVM"] });
|
|
41
|
+
this.para = para;
|
|
42
|
+
this.messageSigningTimeoutMs = messageSigningTimeoutMs;
|
|
43
|
+
}
|
|
44
|
+
async getAddress() {
|
|
45
|
+
return this.para.wallets[this.currentWalletId].address;
|
|
46
|
+
}
|
|
47
|
+
connect(provider) {
|
|
48
|
+
return new _ParaEthersSigner(this.para, provider, this.currentWalletId);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Signs a message.
|
|
52
|
+
*
|
|
53
|
+
* @param message - the message to be signed
|
|
54
|
+
**/
|
|
55
|
+
async signMessage(message) {
|
|
56
|
+
const hashedMessage = import_ethers.ethers.hashMessage(message);
|
|
57
|
+
const base64HashedMessage = (0, import_core_sdk.hexStringToBase64)(hashedMessage);
|
|
58
|
+
const res = await this.para.signMessage({
|
|
59
|
+
walletId: this.currentWalletId,
|
|
60
|
+
messageBase64: base64HashedMessage,
|
|
61
|
+
timeoutMs: this.messageSigningTimeoutMs
|
|
62
|
+
});
|
|
63
|
+
const signature = res.signature;
|
|
64
|
+
return `0x${signature}`;
|
|
65
|
+
}
|
|
66
|
+
async validateTx(tx) {
|
|
67
|
+
const { to, from } = await import_ethers.ethers.resolveProperties({
|
|
68
|
+
to: tx.to ? import_ethers.ethers.resolveAddress(tx.to, this.provider) : void 0,
|
|
69
|
+
from: tx.from ? import_ethers.ethers.resolveAddress(tx.from, this.provider) : void 0
|
|
70
|
+
});
|
|
71
|
+
if (to) {
|
|
72
|
+
tx.to = to;
|
|
73
|
+
}
|
|
74
|
+
if (from) {
|
|
75
|
+
tx.from = from;
|
|
76
|
+
}
|
|
77
|
+
if (tx.from) {
|
|
78
|
+
import_ethers.ethers.assertArgument(
|
|
79
|
+
import_ethers.ethers.getAddress(tx.from).toLowerCase() === (await this.getAddress()).toLowerCase(),
|
|
80
|
+
"transaction from address mismatch",
|
|
81
|
+
"tx.from",
|
|
82
|
+
tx.from
|
|
83
|
+
);
|
|
84
|
+
delete tx.from;
|
|
85
|
+
}
|
|
86
|
+
return import_ethers.ethers.Transaction.from(tx);
|
|
87
|
+
}
|
|
88
|
+
async signTransaction(tx) {
|
|
89
|
+
const txObj = await this.validateTx(tx);
|
|
90
|
+
txObj.signature = {
|
|
91
|
+
r: "0x0",
|
|
92
|
+
s: "0x0",
|
|
93
|
+
v: 0
|
|
94
|
+
};
|
|
95
|
+
const res = await this.para.signTransaction({
|
|
96
|
+
walletId: this.currentWalletId,
|
|
97
|
+
rlpEncodedTxBase64: (0, import_core_sdk.hexStringToBase64)(txObj.serialized),
|
|
98
|
+
chainId: `${txObj.chainId}`
|
|
99
|
+
});
|
|
100
|
+
const signature = res.signature;
|
|
101
|
+
const btx = import_ethers.ethers.Transaction.from(tx);
|
|
102
|
+
btx.signature = `0x${signature}`;
|
|
103
|
+
return btx.serialized;
|
|
104
|
+
}
|
|
105
|
+
async signTypedData(domain, types, value) {
|
|
106
|
+
const populated = await import_ethers.ethers.TypedDataEncoder.resolveNames(domain, types, value, async (name) => {
|
|
107
|
+
import_ethers.ethers.assert(this.provider != null, "cannot resolve ENS names without a provider", "UNSUPPORTED_OPERATION", {
|
|
108
|
+
operation: "resolveName",
|
|
109
|
+
info: { name }
|
|
110
|
+
});
|
|
111
|
+
const address = await this.provider.resolveName(name);
|
|
112
|
+
import_ethers.ethers.assert(address != null, "unconfigured ENS name", "UNCONFIGURED_NAME", {
|
|
113
|
+
value: name
|
|
114
|
+
});
|
|
115
|
+
return address;
|
|
116
|
+
});
|
|
117
|
+
const res = await this.para.signMessage({
|
|
118
|
+
walletId: this.currentWalletId,
|
|
119
|
+
messageBase64: (0, import_core_sdk.hexStringToBase64)(import_ethers.ethers.TypedDataEncoder.hash(populated.domain, types, populated.value))
|
|
120
|
+
});
|
|
121
|
+
const signature = res.signature;
|
|
122
|
+
return `0x${signature}`;
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
126
|
+
0 && (module.exports = {
|
|
127
|
+
ParaEthersSigner
|
|
128
|
+
});
|
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,102 @@
|
|
|
1
|
-
|
|
1
|
+
// src/ethersSigner.ts
|
|
2
|
+
import { ethers } from "ethers";
|
|
3
|
+
import { hexStringToBase64 } from "@getpara/core-sdk";
|
|
4
|
+
var ParaEthersSigner = class _ParaEthersSigner extends ethers.AbstractSigner {
|
|
5
|
+
/**
|
|
6
|
+
* Signs a message.
|
|
7
|
+
*
|
|
8
|
+
* @param para - the ParaCore instance
|
|
9
|
+
* @param provider - the ethers provider to use. If not present, will use the default ethers.Provider.
|
|
10
|
+
* @param walletId - optional wallet ID to use. If not present, will use the first wallet found.
|
|
11
|
+
* @param messageSigningTimeoutMs - optional timeout in milliseconds. If not present, defaults to 30 seconds.
|
|
12
|
+
**/
|
|
13
|
+
constructor(para, provider, walletId, messageSigningTimeoutMs) {
|
|
14
|
+
super(provider);
|
|
15
|
+
this.currentWalletId = para.findWalletId(walletId, { type: ["EVM"] });
|
|
16
|
+
this.para = para;
|
|
17
|
+
this.messageSigningTimeoutMs = messageSigningTimeoutMs;
|
|
18
|
+
}
|
|
19
|
+
async getAddress() {
|
|
20
|
+
return this.para.wallets[this.currentWalletId].address;
|
|
21
|
+
}
|
|
22
|
+
connect(provider) {
|
|
23
|
+
return new _ParaEthersSigner(this.para, provider, this.currentWalletId);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Signs a message.
|
|
27
|
+
*
|
|
28
|
+
* @param message - the message to be signed
|
|
29
|
+
**/
|
|
30
|
+
async signMessage(message) {
|
|
31
|
+
const hashedMessage = ethers.hashMessage(message);
|
|
32
|
+
const base64HashedMessage = hexStringToBase64(hashedMessage);
|
|
33
|
+
const res = await this.para.signMessage({
|
|
34
|
+
walletId: this.currentWalletId,
|
|
35
|
+
messageBase64: base64HashedMessage,
|
|
36
|
+
timeoutMs: this.messageSigningTimeoutMs
|
|
37
|
+
});
|
|
38
|
+
const signature = res.signature;
|
|
39
|
+
return `0x${signature}`;
|
|
40
|
+
}
|
|
41
|
+
async validateTx(tx) {
|
|
42
|
+
const { to, from } = await ethers.resolveProperties({
|
|
43
|
+
to: tx.to ? ethers.resolveAddress(tx.to, this.provider) : void 0,
|
|
44
|
+
from: tx.from ? ethers.resolveAddress(tx.from, this.provider) : void 0
|
|
45
|
+
});
|
|
46
|
+
if (to) {
|
|
47
|
+
tx.to = to;
|
|
48
|
+
}
|
|
49
|
+
if (from) {
|
|
50
|
+
tx.from = from;
|
|
51
|
+
}
|
|
52
|
+
if (tx.from) {
|
|
53
|
+
ethers.assertArgument(
|
|
54
|
+
ethers.getAddress(tx.from).toLowerCase() === (await this.getAddress()).toLowerCase(),
|
|
55
|
+
"transaction from address mismatch",
|
|
56
|
+
"tx.from",
|
|
57
|
+
tx.from
|
|
58
|
+
);
|
|
59
|
+
delete tx.from;
|
|
60
|
+
}
|
|
61
|
+
return ethers.Transaction.from(tx);
|
|
62
|
+
}
|
|
63
|
+
async signTransaction(tx) {
|
|
64
|
+
const txObj = await this.validateTx(tx);
|
|
65
|
+
txObj.signature = {
|
|
66
|
+
r: "0x0",
|
|
67
|
+
s: "0x0",
|
|
68
|
+
v: 0
|
|
69
|
+
};
|
|
70
|
+
const res = await this.para.signTransaction({
|
|
71
|
+
walletId: this.currentWalletId,
|
|
72
|
+
rlpEncodedTxBase64: hexStringToBase64(txObj.serialized),
|
|
73
|
+
chainId: `${txObj.chainId}`
|
|
74
|
+
});
|
|
75
|
+
const signature = res.signature;
|
|
76
|
+
const btx = ethers.Transaction.from(tx);
|
|
77
|
+
btx.signature = `0x${signature}`;
|
|
78
|
+
return btx.serialized;
|
|
79
|
+
}
|
|
80
|
+
async signTypedData(domain, types, value) {
|
|
81
|
+
const populated = await ethers.TypedDataEncoder.resolveNames(domain, types, value, async (name) => {
|
|
82
|
+
ethers.assert(this.provider != null, "cannot resolve ENS names without a provider", "UNSUPPORTED_OPERATION", {
|
|
83
|
+
operation: "resolveName",
|
|
84
|
+
info: { name }
|
|
85
|
+
});
|
|
86
|
+
const address = await this.provider.resolveName(name);
|
|
87
|
+
ethers.assert(address != null, "unconfigured ENS name", "UNCONFIGURED_NAME", {
|
|
88
|
+
value: name
|
|
89
|
+
});
|
|
90
|
+
return address;
|
|
91
|
+
});
|
|
92
|
+
const res = await this.para.signMessage({
|
|
93
|
+
walletId: this.currentWalletId,
|
|
94
|
+
messageBase64: hexStringToBase64(ethers.TypedDataEncoder.hash(populated.domain, types, populated.value))
|
|
95
|
+
});
|
|
96
|
+
const signature = res.signature;
|
|
97
|
+
return `0x${signature}`;
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
export {
|
|
101
|
+
ParaEthersSigner
|
|
102
|
+
};
|
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-v6-integration",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.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.5.0"
|
|
11
11
|
},
|
|
12
12
|
"scripts": {
|
|
13
13
|
"build": "rm -rf dist && node ./scripts/build.mjs && yarn build:types",
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"types": "./dist/types/index.d.ts"
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "0e3c1401b4f1da60b288cdde7695077c9bcbc48f"
|
|
38
38
|
}
|