@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 CHANGED
@@ -1 +1,114 @@
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});
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
+ });
Binary file
Binary file
package/dist/esm/index.js CHANGED
@@ -1 +1,88 @@
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};
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
+ };
Binary file
Binary file
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@getpara/ethers-v5-integration",
3
- "version": "1.4.2",
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.2",
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": "8404d1f8461109347360fe21be6057f826d31cec"
34
+ "gitHead": "9a4086c4b352fff2143d3b931d288c5ebaf127fb"
35
35
  }