@snapshot-labs/snapshot.js 0.4.110 → 0.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/sign/index.d.ts +2 -1
- package/dist/snapshot.cjs.js +9 -7
- package/dist/snapshot.esm.js +9 -7
- package/dist/snapshot.min.js +1 -1
- package/package.json +1 -1
- package/src/sign/index.ts +7 -3
package/package.json
CHANGED
package/src/sign/index.ts
CHANGED
|
@@ -47,8 +47,9 @@ export const domain = {
|
|
|
47
47
|
|
|
48
48
|
export default class Client {
|
|
49
49
|
readonly address: string;
|
|
50
|
+
readonly options: any;
|
|
50
51
|
|
|
51
|
-
constructor(address: string = constants.livenet.sequencer) {
|
|
52
|
+
constructor(address: string = constants.livenet.sequencer, options = {}) {
|
|
52
53
|
address = address.replace(
|
|
53
54
|
constants.livenet.hub,
|
|
54
55
|
constants.livenet.sequencer
|
|
@@ -59,6 +60,7 @@ export default class Client {
|
|
|
59
60
|
);
|
|
60
61
|
address = address.replace(constants.local.hub, constants.local.sequencer);
|
|
61
62
|
this.address = address;
|
|
63
|
+
this.options = options;
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
async sign(web3: Web3Provider | Wallet, address: string, message, types) {
|
|
@@ -70,11 +72,13 @@ export default class Client {
|
|
|
70
72
|
message.timestamp = parseInt((Date.now() / 1e3).toFixed());
|
|
71
73
|
const data: any = { domain, types, message };
|
|
72
74
|
const sig = await signer._signTypedData(domain, data.types, message);
|
|
73
|
-
//console.log('Sign', { address: checksumAddress, sig, data });
|
|
74
75
|
return await this.send({ address: checksumAddress, sig, data });
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
async send(envelop) {
|
|
79
|
+
let address = this.address;
|
|
80
|
+
if (envelop.sig === '0x' && this.options.relayerURL)
|
|
81
|
+
address = this.options.relayerURL;
|
|
78
82
|
const init = {
|
|
79
83
|
method: 'POST',
|
|
80
84
|
headers: {
|
|
@@ -84,7 +88,7 @@ export default class Client {
|
|
|
84
88
|
body: JSON.stringify(envelop)
|
|
85
89
|
};
|
|
86
90
|
return new Promise((resolve, reject) => {
|
|
87
|
-
fetch(
|
|
91
|
+
fetch(address, init)
|
|
88
92
|
.then((res) => {
|
|
89
93
|
if (res.ok) return resolve(res.json());
|
|
90
94
|
throw res;
|