@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 CHANGED
@@ -1 +1,128 @@
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});
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
+ });
Binary file
Binary file
package/dist/esm/index.js CHANGED
@@ -1 +1,102 @@
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};
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
+ };
Binary file
Binary file
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@getpara/ethers-v6-integration",
3
- "version": "1.4.3",
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.4.3"
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": "1af7abd51e994057ff4afc90bd13650a47f6b26e"
37
+ "gitHead": "0e3c1401b4f1da60b288cdde7695077c9bcbc48f"
38
38
  }