@getpara/ethers-v5-integration 1.2.0 → 1.3.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 CHANGED
@@ -1,17 +1 @@
1
- "use strict";
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 d=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var f=Object.prototype.hasOwnProperty;var y=(a,e)=>{for(var r in e)d(a,r,{get:e[r],enumerable:!0})},v=(a,e,r,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of m(e))!f.call(a,t)&&t!==r&&d(a,t,{get:()=>e[t],enumerable:!(s=w(e,t))||s.enumerable});return a};var T=a=>v(d({},"__esModule",{value:!0}),a);var I={};y(I,{ParaEthersV5Signer:()=>c});module.exports=T(I);var n=require("ethers"),g=require("@ethersproject/hash"),o=require("@getpara/core-sdk"),i=require("ethers/lib/utils"),c=class a extends n.ethers.Signer{constructor(e,r,s){super(),this.currentWalletId=e.findWalletId(s,{type:["EVM"]}),this.para=e,(0,i.defineReadOnly)(this,"provider",r)}setCurrentWalletId(e){if(!this.para.wallets[e])throw new Error(`no wallet exists with id ${e}`);this.currentWalletId=e}getCurrentWalletId(){let e=this.currentWalletId;if(!e)throw new Error("no wallet available");if(!this.para.wallets[e])throw new Error(`no wallet exists with id ${e}`);return e}async getAddress(){let e=this.getCurrentWalletId();if(!e)throw new Error("no wallet available");return this.para.wallets[e].address}connect(e){return new a(this.para,e,this.currentWalletId)}async signMessage(e){let r=n.ethers.utils.hashMessage(e),s=(0,o.hexStringToBase64)(r);return`0x${(await this.para.signMessage({walletId:this.getCurrentWalletId(),messageBase64:s})).signature}`}async signTransaction(e){return(0,i.resolveProperties)(e).then(async r=>{if(r.from!=null){if((await this.getAddress()).toLowerCase()!==n.ethers.utils.getAddress(r.from).toLowerCase())throw new Error("transaction from address mismatch");delete r.from}let s=r;s.r="0x0",s.s="0x0",s.v=0;let t=(0,i.serializeTransaction)(s),l=(0,o.hexStringToBase64)((0,i.keccak256)(t)),h=await this.signMessage(l);return(0,i.serializeTransaction)(s,h)})}async signTypedData(e,r,s){let t=await g._TypedDataEncoder.resolveNames(e,r,s,async p=>{if(!this.provider)throw new Error("cannot resolve ENS names without a provider");let u=await this.provider.resolveName(p);if(!u)throw new Error("unconfigured ENS name");return u});return`0x${(await this.para.signMessage({walletId:this.getCurrentWalletId(),messageBase64:(0,o.hexStringToBase64)(g._TypedDataEncoder.hash(t.domain,r,t.value))})).signature}`}async _signTypedData(e,r,s){return this.signTypedData(e,r,s)}};0&&(module.exports={ParaEthersV5Signer});
Binary file
Binary file
package/dist/esm/index.js CHANGED
@@ -1 +1 @@
1
- export * from './ethersSigner.js';
1
+ import{ethers as i}from"ethers";import{_TypedDataEncoder as d}from"@ethersproject/hash";import{hexStringToBase64 as n}from"@getpara/core-sdk";import{defineReadOnly as p,keccak256 as w,resolveProperties as m,serializeTransaction as g}from"ethers/lib/utils";var c=class h extends i.Signer{constructor(e,r,s){super(),this.currentWalletId=e.findWalletId(s,{type:["EVM"]}),this.para=e,p(this,"provider",r)}setCurrentWalletId(e){if(!this.para.wallets[e])throw new Error(`no wallet exists with id ${e}`);this.currentWalletId=e}getCurrentWalletId(){let e=this.currentWalletId;if(!e)throw new Error("no wallet available");if(!this.para.wallets[e])throw new Error(`no wallet exists with id ${e}`);return e}async getAddress(){let e=this.getCurrentWalletId();if(!e)throw new Error("no wallet available");return this.para.wallets[e].address}connect(e){return new h(this.para,e,this.currentWalletId)}async signMessage(e){let r=i.utils.hashMessage(e),s=n(r);return`0x${(await this.para.signMessage({walletId:this.getCurrentWalletId(),messageBase64:s})).signature}`}async signTransaction(e){return m(e).then(async r=>{if(r.from!=null){if((await this.getAddress()).toLowerCase()!==i.utils.getAddress(r.from).toLowerCase())throw new Error("transaction from address mismatch");delete r.from}let s=r;s.r="0x0",s.s="0x0",s.v=0;let t=g(s),a=n(w(t)),o=await this.signMessage(a);return g(s,o)})}async signTypedData(e,r,s){let t=await d.resolveNames(e,r,s,async u=>{if(!this.provider)throw new Error("cannot resolve ENS names without a provider");let l=await this.provider.resolveName(u);if(!l)throw new Error("unconfigured ENS name");return l});return`0x${(await this.para.signMessage({walletId:this.getCurrentWalletId(),messageBase64:n(d.hash(t.domain,r,t.value))})).signature}`}async _signTypedData(e,r,s){return this.signTypedData(e,r,s)}};export{c as ParaEthersV5Signer};
Binary file
Binary file
package/package.json CHANGED
@@ -1,17 +1,18 @@
1
1
  {
2
2
  "name": "@getpara/ethers-v5-integration",
3
- "version": "1.2.0",
3
+ "version": "1.3.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.2.0",
10
+ "@getpara/core-sdk": "1.3.0",
11
11
  "ethers": "^5.7.2"
12
12
  },
13
13
  "scripts": {
14
- "build": "yarn build:cjs && yarn build:esm && yarn build:types",
14
+ "build": "rm -rf dist && node ./scripts/build.mjs && yarn build:types",
15
+ "old-build": "yarn build:cjs && yarn build:esm && yarn build:types",
15
16
  "build:cjs": "rm -rf dist/cjs && tsc --module commonjs --outDir dist/cjs && printf '{\"type\":\"commonjs\"}' > dist/cjs/package.json",
16
17
  "build:esm": "rm -rf dist/esm && tsc --module es6 --outDir dist/esm && printf '{\"type\":\"module\",\"sideEffects\":false}' > dist/esm/package.json",
17
18
  "build:types": "rm -rf dist/types && tsc --module es6 --declarationDir dist/types --emitDeclarationOnly --declaration"
@@ -30,5 +31,5 @@
30
31
  "types": "./dist/types/index.d.ts"
31
32
  }
32
33
  },
33
- "gitHead": "a9162c59be1456292d46c56787c1d5bf313bf24b"
34
+ "gitHead": "2d421556a0a1497abd08e18dca94f08ec3ad640b"
34
35
  }
@@ -1,107 +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.ParaEthersV5Signer = void 0;
13
- const ethers_1 = require("ethers");
14
- const hash_1 = require("@ethersproject/hash");
15
- const core_sdk_1 = require("@getpara/core-sdk");
16
- const utils_1 = require("ethers/lib/utils");
17
- class ParaEthersV5Signer extends ethers_1.ethers.Signer {
18
- constructor(para, provider, walletId) {
19
- super();
20
- this.currentWalletId = para.findWalletId(walletId, { type: ['EVM'] });
21
- this.para = para;
22
- (0, utils_1.defineReadOnly)(this, 'provider', provider);
23
- }
24
- setCurrentWalletId(walletId) {
25
- if (!this.para.wallets[walletId]) {
26
- throw new Error(`no wallet exists with id ${walletId}`);
27
- }
28
- this.currentWalletId = walletId;
29
- }
30
- getCurrentWalletId() {
31
- const id = this.currentWalletId;
32
- if (!id) {
33
- throw new Error(`no wallet available`);
34
- }
35
- if (!this.para.wallets[id]) {
36
- throw new Error(`no wallet exists with id ${id}`);
37
- }
38
- return id;
39
- }
40
- getAddress() {
41
- return __awaiter(this, void 0, void 0, function* () {
42
- const walletId = this.getCurrentWalletId();
43
- if (!walletId) {
44
- throw new Error('no wallet available');
45
- }
46
- return this.para.wallets[walletId].address;
47
- });
48
- }
49
- connect(provider) {
50
- return new ParaEthersV5Signer(this.para, provider, this.currentWalletId);
51
- }
52
- signMessage(message) {
53
- return __awaiter(this, void 0, void 0, function* () {
54
- const hashedMessage = ethers_1.ethers.utils.hashMessage(message);
55
- const base64HashedMessage = (0, core_sdk_1.hexStringToBase64)(hashedMessage);
56
- const res = yield this.para.signMessage({ walletId: this.getCurrentWalletId(), messageBase64: base64HashedMessage });
57
- const signature = res.signature;
58
- return `0x${signature}`;
59
- });
60
- }
61
- signTransaction(tx) {
62
- return __awaiter(this, void 0, void 0, function* () {
63
- return (0, utils_1.resolveProperties)(tx).then((tx) => __awaiter(this, void 0, void 0, function* () {
64
- if (tx.from != null) {
65
- if ((yield this.getAddress()).toLowerCase() !== ethers_1.ethers.utils.getAddress(tx.from).toLowerCase()) {
66
- throw new Error('transaction from address mismatch');
67
- }
68
- delete tx.from;
69
- }
70
- let txObj = tx;
71
- txObj.r = '0x0';
72
- txObj.s = '0x0';
73
- txObj.v = 0;
74
- const serializedTx = (0, utils_1.serializeTransaction)(txObj);
75
- const message = (0, core_sdk_1.hexStringToBase64)((0, utils_1.keccak256)(serializedTx));
76
- const signature = yield this.signMessage(message);
77
- return (0, utils_1.serializeTransaction)(txObj, signature);
78
- }));
79
- });
80
- }
81
- signTypedData(domain, types, value) {
82
- return __awaiter(this, void 0, void 0, function* () {
83
- const populated = yield hash_1._TypedDataEncoder.resolveNames(domain, types, value, (name) => __awaiter(this, void 0, void 0, function* () {
84
- if (!this.provider) {
85
- throw new Error('cannot resolve ENS names without a provider');
86
- }
87
- const address = yield this.provider.resolveName(name);
88
- if (!address) {
89
- throw new Error('unconfigured ENS name');
90
- }
91
- return address;
92
- }));
93
- const res = yield this.para.signMessage({
94
- walletId: this.getCurrentWalletId(),
95
- messageBase64: (0, core_sdk_1.hexStringToBase64)(hash_1._TypedDataEncoder.hash(populated.domain, types, populated.value)),
96
- });
97
- const signature = res.signature;
98
- return `0x${signature}`;
99
- });
100
- }
101
- _signTypedData(domain, types, value) {
102
- return __awaiter(this, void 0, void 0, function* () {
103
- return this.signTypedData(domain, types, value);
104
- });
105
- }
106
- }
107
- exports.ParaEthersV5Signer = ParaEthersV5Signer;
@@ -1 +0,0 @@
1
- {"type":"commonjs"}
@@ -1,103 +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 { _TypedDataEncoder } from '@ethersproject/hash';
12
- import { hexStringToBase64 } from '@getpara/core-sdk';
13
- import { defineReadOnly, keccak256, resolveProperties, serializeTransaction } from 'ethers/lib/utils';
14
- export class ParaEthersV5Signer extends ethers.Signer {
15
- constructor(para, provider, walletId) {
16
- super();
17
- this.currentWalletId = para.findWalletId(walletId, { type: ['EVM'] });
18
- this.para = para;
19
- defineReadOnly(this, 'provider', provider);
20
- }
21
- setCurrentWalletId(walletId) {
22
- if (!this.para.wallets[walletId]) {
23
- throw new Error(`no wallet exists with id ${walletId}`);
24
- }
25
- this.currentWalletId = walletId;
26
- }
27
- getCurrentWalletId() {
28
- const id = this.currentWalletId;
29
- if (!id) {
30
- throw new Error(`no wallet available`);
31
- }
32
- if (!this.para.wallets[id]) {
33
- throw new Error(`no wallet exists with id ${id}`);
34
- }
35
- return id;
36
- }
37
- getAddress() {
38
- return __awaiter(this, void 0, void 0, function* () {
39
- const walletId = this.getCurrentWalletId();
40
- if (!walletId) {
41
- throw new Error('no wallet available');
42
- }
43
- return this.para.wallets[walletId].address;
44
- });
45
- }
46
- connect(provider) {
47
- return new ParaEthersV5Signer(this.para, provider, this.currentWalletId);
48
- }
49
- signMessage(message) {
50
- return __awaiter(this, void 0, void 0, function* () {
51
- const hashedMessage = ethers.utils.hashMessage(message);
52
- const base64HashedMessage = hexStringToBase64(hashedMessage);
53
- const res = yield this.para.signMessage({ walletId: this.getCurrentWalletId(), messageBase64: base64HashedMessage });
54
- const signature = res.signature;
55
- return `0x${signature}`;
56
- });
57
- }
58
- signTransaction(tx) {
59
- return __awaiter(this, void 0, void 0, function* () {
60
- return resolveProperties(tx).then((tx) => __awaiter(this, void 0, void 0, function* () {
61
- if (tx.from != null) {
62
- if ((yield this.getAddress()).toLowerCase() !== ethers.utils.getAddress(tx.from).toLowerCase()) {
63
- throw new Error('transaction from address mismatch');
64
- }
65
- delete tx.from;
66
- }
67
- let txObj = tx;
68
- txObj.r = '0x0';
69
- txObj.s = '0x0';
70
- txObj.v = 0;
71
- const serializedTx = serializeTransaction(txObj);
72
- const message = hexStringToBase64(keccak256(serializedTx));
73
- const signature = yield this.signMessage(message);
74
- return serializeTransaction(txObj, signature);
75
- }));
76
- });
77
- }
78
- signTypedData(domain, types, value) {
79
- return __awaiter(this, void 0, void 0, function* () {
80
- const populated = yield _TypedDataEncoder.resolveNames(domain, types, value, (name) => __awaiter(this, void 0, void 0, function* () {
81
- if (!this.provider) {
82
- throw new Error('cannot resolve ENS names without a provider');
83
- }
84
- const address = yield this.provider.resolveName(name);
85
- if (!address) {
86
- throw new Error('unconfigured ENS name');
87
- }
88
- return address;
89
- }));
90
- const res = yield this.para.signMessage({
91
- walletId: this.getCurrentWalletId(),
92
- messageBase64: hexStringToBase64(_TypedDataEncoder.hash(populated.domain, types, populated.value)),
93
- });
94
- const signature = res.signature;
95
- return `0x${signature}`;
96
- });
97
- }
98
- _signTypedData(domain, types, value) {
99
- return __awaiter(this, void 0, void 0, function* () {
100
- return this.signTypedData(domain, types, value);
101
- });
102
- }
103
- }
@@ -1 +0,0 @@
1
- {"type":"module","sideEffects":false}