Skip to content

Commit a2db2c0

Browse files
authored
Fallback to relayer if signature is 0x (#880)
* Fallback to relayer * Update src/sign/index.ts * v0.5.0
1 parent 6ec7c66 commit a2db2c0

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@snapshot-labs/snapshot.js",
3-
"version": "0.4.110",
3+
"version": "0.5.0",
44
"repository": "snapshot-labs/snapshot.js",
55
"license": "MIT",
66
"main": "dist/snapshot.cjs.js",

src/sign/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ export const domain = {
4747

4848
export default class Client {
4949
readonly address: string;
50+
readonly options: any;
5051

51-
constructor(address: string = constants.livenet.sequencer) {
52+
constructor(address: string = constants.livenet.sequencer, options = {}) {
5253
address = address.replace(
5354
constants.livenet.hub,
5455
constants.livenet.sequencer
@@ -59,6 +60,7 @@ export default class Client {
5960
);
6061
address = address.replace(constants.local.hub, constants.local.sequencer);
6162
this.address = address;
63+
this.options = options;
6264
}
6365

6466
async sign(web3: Web3Provider | Wallet, address: string, message, types) {
@@ -70,11 +72,13 @@ export default class Client {
7072
message.timestamp = parseInt((Date.now() / 1e3).toFixed());
7173
const data: any = { domain, types, message };
7274
const sig = await signer._signTypedData(domain, data.types, message);
73-
//console.log('Sign', { address: checksumAddress, sig, data });
7475
return await this.send({ address: checksumAddress, sig, data });
7576
}
7677

7778
async send(envelop) {
79+
let address = this.address;
80+
if (envelop.sig === '0x' && this.options.relayerURL)
81+
address = this.options.relayerURL;
7882
const init = {
7983
method: 'POST',
8084
headers: {
@@ -84,7 +88,7 @@ export default class Client {
8488
body: JSON.stringify(envelop)
8589
};
8690
return new Promise((resolve, reject) => {
87-
fetch(this.address, init)
91+
fetch(address, init)
8892
.then((res) => {
8993
if (res.ok) return resolve(res.json());
9094
throw res;

0 commit comments

Comments
 (0)