@getpara/ethers-v6-integration 1.2.0 → 1.3.1
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 +1 -17
- package/dist/cjs/index.js.br +0 -0
- package/dist/cjs/index.js.gz +0 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.br +0 -0
- package/dist/esm/index.js.gz +0 -0
- package/package.json +5 -4
- package/dist/cjs/ethersSigner.js +0 -116
- package/dist/cjs/package.json +0 -1
- package/dist/esm/ethersSigner.js +0 -112
- package/dist/esm/package.json +0 -1
package/dist/cjs/index.js
CHANGED
|
@@ -1,17 +1 @@
|
|
|
1
|
-
"
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./ethersSigner.js"), exports);
|
|
1
|
+
var c=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var p=(i,e)=>{for(var s in e)c(i,s,{get:e[s],enumerable:!0})},f=(i,e,s,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of h(e))!m.call(i,t)&&t!==s&&c(i,t,{get:()=>e[t],enumerable:!(a=l(e,t))||a.enumerable});return i};var v=i=>f(c({},"__esModule",{value:!0}),i);var T={};p(T,{ParaEthersSigner:()=>u});module.exports=v(T);var r=require("ethers"),o=require("@getpara/core-sdk"),u=class i extends r.ethers.AbstractSigner{constructor(e,s,a,t){super(s),this.currentWalletId=e.findWalletId(a,{type:["EVM"]}),this.para=e,this.messageSigningTimeoutMs=t}async getAddress(){return this.para.wallets[this.currentWalletId].address}connect(e){return new i(this.para,e,this.currentWalletId)}async signMessage(e){let s=r.ethers.hashMessage(e),a=(0,o.hexStringToBase64)(s);return`0x${(await this.para.signMessage({walletId:this.currentWalletId,messageBase64:a,timeoutMs:this.messageSigningTimeoutMs})).signature}`}async validateTx(e){let{to:s,from:a}=await r.ethers.resolveProperties({to:e.to?r.ethers.resolveAddress(e.to,this.provider):void 0,from:e.from?r.ethers.resolveAddress(e.from,this.provider):void 0});return s&&(e.to=s),a&&(e.from=a),e.from&&(r.ethers.assertArgument(r.ethers.getAddress(e.from).toLowerCase()===(await this.getAddress()).toLowerCase(),"transaction from address mismatch","tx.from",e.from),delete e.from),r.ethers.Transaction.from(e)}async signTransaction(e){let s=await this.validateTx(e);s.signature={r:"0x0",s:"0x0",v:0};let t=(await this.para.signTransaction({walletId:this.currentWalletId,rlpEncodedTxBase64:(0,o.hexStringToBase64)(s.serialized),chainId:`${s.chainId}`})).signature,n=r.ethers.Transaction.from(e);return n.signature=`0x${t}`,n.serialized}async signTypedData(e,s,a){let t=await r.ethers.TypedDataEncoder.resolveNames(e,s,a,async d=>{r.ethers.assert(this.provider!=null,"cannot resolve ENS names without a provider","UNSUPPORTED_OPERATION",{operation:"resolveName",info:{name:d}});let g=await this.provider.resolveName(d);return r.ethers.assert(g!=null,"unconfigured ENS name","UNCONFIGURED_NAME",{value:d}),g});return`0x${(await this.para.signMessage({walletId:this.currentWalletId,messageBase64:(0,o.hexStringToBase64)(r.ethers.TypedDataEncoder.hash(t.domain,s,t.value))})).signature}`}};0&&(module.exports={ParaEthersSigner});
|
|
Binary file
|
|
Binary file
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{ethers as r}from"ethers";import{hexStringToBase64 as o}from"@getpara/core-sdk";var c=class u extends r.AbstractSigner{constructor(e,s,t,a){super(s),this.currentWalletId=e.findWalletId(t,{type:["EVM"]}),this.para=e,this.messageSigningTimeoutMs=a}async getAddress(){return this.para.wallets[this.currentWalletId].address}connect(e){return new u(this.para,e,this.currentWalletId)}async signMessage(e){let s=r.hashMessage(e),t=o(s);return`0x${(await this.para.signMessage({walletId:this.currentWalletId,messageBase64:t,timeoutMs:this.messageSigningTimeoutMs})).signature}`}async validateTx(e){let{to:s,from:t}=await r.resolveProperties({to:e.to?r.resolveAddress(e.to,this.provider):void 0,from:e.from?r.resolveAddress(e.from,this.provider):void 0});return s&&(e.to=s),t&&(e.from=t),e.from&&(r.assertArgument(r.getAddress(e.from).toLowerCase()===(await this.getAddress()).toLowerCase(),"transaction from address mismatch","tx.from",e.from),delete e.from),r.Transaction.from(e)}async signTransaction(e){let s=await this.validateTx(e);s.signature={r:"0x0",s:"0x0",v:0};let a=(await this.para.signTransaction({walletId:this.currentWalletId,rlpEncodedTxBase64:o(s.serialized),chainId:`${s.chainId}`})).signature,i=r.Transaction.from(e);return i.signature=`0x${a}`,i.serialized}async signTypedData(e,s,t){let a=await r.TypedDataEncoder.resolveNames(e,s,t,async n=>{r.assert(this.provider!=null,"cannot resolve ENS names without a provider","UNSUPPORTED_OPERATION",{operation:"resolveName",info:{name:n}});let d=await this.provider.resolveName(n);return r.assert(d!=null,"unconfigured ENS name","UNCONFIGURED_NAME",{value:n}),d});return`0x${(await this.para.signMessage({walletId:this.currentWalletId,messageBase64:o(r.TypedDataEncoder.hash(a.domain,s,a.value))})).signature}`}};export{c as ParaEthersSigner};
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getpara/ethers-v6-integration",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
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.3.1"
|
|
11
11
|
},
|
|
12
12
|
"scripts": {
|
|
13
|
-
"build": "
|
|
13
|
+
"build": "rm -rf dist && node ./scripts/build.mjs && yarn build:types",
|
|
14
|
+
"old-build": "yarn build:cjs && yarn build:esm && yarn build:types",
|
|
14
15
|
"build:cjs": "rm -rf dist/cjs && tsc --module commonjs --outDir dist/cjs && printf '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
|
|
15
16
|
"build:esm": "rm -rf dist/esm && tsc --module es6 --outDir dist/esm && printf '{\"type\":\"module\",\"sideEffects\":false}' > dist/esm/package.json",
|
|
16
17
|
"build:types": "rm -rf dist/types && tsc --module es6 --declarationDir dist/types --emitDeclarationOnly --declaration"
|
|
@@ -33,5 +34,5 @@
|
|
|
33
34
|
"types": "./dist/types/index.d.ts"
|
|
34
35
|
}
|
|
35
36
|
},
|
|
36
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "a35e01b55fde3220d50ead988b1c18f8442a9db4"
|
|
37
38
|
}
|
package/dist/cjs/ethersSigner.js
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.ParaEthersSigner = void 0;
|
|
13
|
-
const ethers_1 = require("ethers");
|
|
14
|
-
const core_sdk_1 = require("@getpara/core-sdk");
|
|
15
|
-
class ParaEthersSigner extends ethers_1.ethers.AbstractSigner {
|
|
16
|
-
/**
|
|
17
|
-
* Signs a message.
|
|
18
|
-
*
|
|
19
|
-
* @param para - the ParaCore instance
|
|
20
|
-
* @param provider - the ethers provider to use. If not present, will use the default ethers.Provider.
|
|
21
|
-
* @param walletId - optional wallet ID to use. If not present, will use the first wallet found.
|
|
22
|
-
* @param messageSigningTimeoutMs - optional timeout in milliseconds. If not present, defaults to 30 seconds.
|
|
23
|
-
**/
|
|
24
|
-
constructor(para, provider, walletId, messageSigningTimeoutMs) {
|
|
25
|
-
super(provider);
|
|
26
|
-
this.currentWalletId = para.findWalletId(walletId, { type: ['EVM'] });
|
|
27
|
-
this.para = para;
|
|
28
|
-
this.messageSigningTimeoutMs = messageSigningTimeoutMs;
|
|
29
|
-
}
|
|
30
|
-
getAddress() {
|
|
31
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
-
return this.para.wallets[this.currentWalletId].address;
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
connect(provider) {
|
|
36
|
-
return new ParaEthersSigner(this.para, provider, this.currentWalletId);
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Signs a message.
|
|
40
|
-
*
|
|
41
|
-
* @param message - the message to be signed
|
|
42
|
-
**/
|
|
43
|
-
signMessage(message) {
|
|
44
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
-
const hashedMessage = ethers_1.ethers.hashMessage(message);
|
|
46
|
-
const base64HashedMessage = (0, core_sdk_1.hexStringToBase64)(hashedMessage);
|
|
47
|
-
const res = yield this.para.signMessage({
|
|
48
|
-
walletId: this.currentWalletId,
|
|
49
|
-
messageBase64: base64HashedMessage,
|
|
50
|
-
timeoutMs: this.messageSigningTimeoutMs,
|
|
51
|
-
});
|
|
52
|
-
const signature = res.signature;
|
|
53
|
-
return `0x${signature}`;
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
validateTx(tx) {
|
|
57
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
-
const { to, from } = yield ethers_1.ethers.resolveProperties({
|
|
59
|
-
to: tx.to ? ethers_1.ethers.resolveAddress(tx.to, this.provider) : undefined,
|
|
60
|
-
from: tx.from ? ethers_1.ethers.resolveAddress(tx.from, this.provider) : undefined,
|
|
61
|
-
});
|
|
62
|
-
if (to) {
|
|
63
|
-
tx.to = to;
|
|
64
|
-
}
|
|
65
|
-
if (from) {
|
|
66
|
-
tx.from = from;
|
|
67
|
-
}
|
|
68
|
-
if (tx.from) {
|
|
69
|
-
ethers_1.ethers.assertArgument(ethers_1.ethers.getAddress(tx.from).toLowerCase() === (yield this.getAddress()).toLowerCase(), 'transaction from address mismatch', 'tx.from', tx.from);
|
|
70
|
-
delete tx.from;
|
|
71
|
-
}
|
|
72
|
-
return ethers_1.ethers.Transaction.from(tx);
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
signTransaction(tx) {
|
|
76
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
77
|
-
const txObj = yield this.validateTx(tx);
|
|
78
|
-
txObj.signature = {
|
|
79
|
-
r: '0x0',
|
|
80
|
-
s: '0x0',
|
|
81
|
-
v: 0,
|
|
82
|
-
};
|
|
83
|
-
const res = yield this.para.signTransaction({
|
|
84
|
-
walletId: this.currentWalletId,
|
|
85
|
-
rlpEncodedTxBase64: (0, core_sdk_1.hexStringToBase64)(txObj.serialized),
|
|
86
|
-
chainId: `${txObj.chainId}`,
|
|
87
|
-
});
|
|
88
|
-
const signature = res.signature;
|
|
89
|
-
const btx = ethers_1.ethers.Transaction.from(tx);
|
|
90
|
-
btx.signature = `0x${signature}`;
|
|
91
|
-
return btx.serialized;
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
signTypedData(domain, types, value) {
|
|
95
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
96
|
-
const populated = yield ethers_1.ethers.TypedDataEncoder.resolveNames(domain, types, value, (name) => __awaiter(this, void 0, void 0, function* () {
|
|
97
|
-
ethers_1.ethers.assert(this.provider != null, 'cannot resolve ENS names without a provider', 'UNSUPPORTED_OPERATION', {
|
|
98
|
-
operation: 'resolveName',
|
|
99
|
-
info: { name },
|
|
100
|
-
});
|
|
101
|
-
const address = yield this.provider.resolveName(name);
|
|
102
|
-
ethers_1.ethers.assert(address != null, 'unconfigured ENS name', 'UNCONFIGURED_NAME', {
|
|
103
|
-
value: name,
|
|
104
|
-
});
|
|
105
|
-
return address;
|
|
106
|
-
}));
|
|
107
|
-
const res = yield this.para.signMessage({
|
|
108
|
-
walletId: this.currentWalletId,
|
|
109
|
-
messageBase64: (0, core_sdk_1.hexStringToBase64)(ethers_1.ethers.TypedDataEncoder.hash(populated.domain, types, populated.value)),
|
|
110
|
-
});
|
|
111
|
-
const signature = res.signature;
|
|
112
|
-
return `0x${signature}`;
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
exports.ParaEthersSigner = ParaEthersSigner;
|
package/dist/cjs/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"commonjs"}
|
package/dist/esm/ethersSigner.js
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { ethers } from 'ethers';
|
|
11
|
-
import { hexStringToBase64 } from '@getpara/core-sdk';
|
|
12
|
-
export class ParaEthersSigner extends ethers.AbstractSigner {
|
|
13
|
-
/**
|
|
14
|
-
* Signs a message.
|
|
15
|
-
*
|
|
16
|
-
* @param para - the ParaCore instance
|
|
17
|
-
* @param provider - the ethers provider to use. If not present, will use the default ethers.Provider.
|
|
18
|
-
* @param walletId - optional wallet ID to use. If not present, will use the first wallet found.
|
|
19
|
-
* @param messageSigningTimeoutMs - optional timeout in milliseconds. If not present, defaults to 30 seconds.
|
|
20
|
-
**/
|
|
21
|
-
constructor(para, provider, walletId, messageSigningTimeoutMs) {
|
|
22
|
-
super(provider);
|
|
23
|
-
this.currentWalletId = para.findWalletId(walletId, { type: ['EVM'] });
|
|
24
|
-
this.para = para;
|
|
25
|
-
this.messageSigningTimeoutMs = messageSigningTimeoutMs;
|
|
26
|
-
}
|
|
27
|
-
getAddress() {
|
|
28
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
-
return this.para.wallets[this.currentWalletId].address;
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
connect(provider) {
|
|
33
|
-
return new ParaEthersSigner(this.para, provider, this.currentWalletId);
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Signs a message.
|
|
37
|
-
*
|
|
38
|
-
* @param message - the message to be signed
|
|
39
|
-
**/
|
|
40
|
-
signMessage(message) {
|
|
41
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
-
const hashedMessage = ethers.hashMessage(message);
|
|
43
|
-
const base64HashedMessage = hexStringToBase64(hashedMessage);
|
|
44
|
-
const res = yield this.para.signMessage({
|
|
45
|
-
walletId: this.currentWalletId,
|
|
46
|
-
messageBase64: base64HashedMessage,
|
|
47
|
-
timeoutMs: this.messageSigningTimeoutMs,
|
|
48
|
-
});
|
|
49
|
-
const signature = res.signature;
|
|
50
|
-
return `0x${signature}`;
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
validateTx(tx) {
|
|
54
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
-
const { to, from } = yield ethers.resolveProperties({
|
|
56
|
-
to: tx.to ? ethers.resolveAddress(tx.to, this.provider) : undefined,
|
|
57
|
-
from: tx.from ? ethers.resolveAddress(tx.from, this.provider) : undefined,
|
|
58
|
-
});
|
|
59
|
-
if (to) {
|
|
60
|
-
tx.to = to;
|
|
61
|
-
}
|
|
62
|
-
if (from) {
|
|
63
|
-
tx.from = from;
|
|
64
|
-
}
|
|
65
|
-
if (tx.from) {
|
|
66
|
-
ethers.assertArgument(ethers.getAddress(tx.from).toLowerCase() === (yield this.getAddress()).toLowerCase(), 'transaction from address mismatch', 'tx.from', tx.from);
|
|
67
|
-
delete tx.from;
|
|
68
|
-
}
|
|
69
|
-
return ethers.Transaction.from(tx);
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
signTransaction(tx) {
|
|
73
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
-
const txObj = yield this.validateTx(tx);
|
|
75
|
-
txObj.signature = {
|
|
76
|
-
r: '0x0',
|
|
77
|
-
s: '0x0',
|
|
78
|
-
v: 0,
|
|
79
|
-
};
|
|
80
|
-
const res = yield this.para.signTransaction({
|
|
81
|
-
walletId: this.currentWalletId,
|
|
82
|
-
rlpEncodedTxBase64: hexStringToBase64(txObj.serialized),
|
|
83
|
-
chainId: `${txObj.chainId}`,
|
|
84
|
-
});
|
|
85
|
-
const signature = res.signature;
|
|
86
|
-
const btx = ethers.Transaction.from(tx);
|
|
87
|
-
btx.signature = `0x${signature}`;
|
|
88
|
-
return btx.serialized;
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
signTypedData(domain, types, value) {
|
|
92
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
-
const populated = yield ethers.TypedDataEncoder.resolveNames(domain, types, value, (name) => __awaiter(this, void 0, void 0, function* () {
|
|
94
|
-
ethers.assert(this.provider != null, 'cannot resolve ENS names without a provider', 'UNSUPPORTED_OPERATION', {
|
|
95
|
-
operation: 'resolveName',
|
|
96
|
-
info: { name },
|
|
97
|
-
});
|
|
98
|
-
const address = yield this.provider.resolveName(name);
|
|
99
|
-
ethers.assert(address != null, 'unconfigured ENS name', 'UNCONFIGURED_NAME', {
|
|
100
|
-
value: name,
|
|
101
|
-
});
|
|
102
|
-
return address;
|
|
103
|
-
}));
|
|
104
|
-
const res = yield this.para.signMessage({
|
|
105
|
-
walletId: this.currentWalletId,
|
|
106
|
-
messageBase64: hexStringToBase64(ethers.TypedDataEncoder.hash(populated.domain, types, populated.value)),
|
|
107
|
-
});
|
|
108
|
-
const signature = res.signature;
|
|
109
|
-
return `0x${signature}`;
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
}
|
package/dist/esm/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"module","sideEffects":false}
|