@0xsequence/guard 1.4.9 → 1.6.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.
@@ -25,11 +25,14 @@ function _extends() {
25
25
  //
26
26
  // Types
27
27
  //
28
+
28
29
  //
29
30
  // Client
30
31
  //
31
32
  class Guard {
32
33
  constructor(hostname, fetch) {
34
+ this.hostname = void 0;
35
+ this.fetch = void 0;
33
36
  this.path = '/rpc/Guard/';
34
37
  this.ping = headers => {
35
38
  return this.fetch(this.url('Ping'), createHTTPRequest({}, headers)).then(res => {
@@ -190,7 +193,6 @@ const buildResponse = res => {
190
193
  if (!res.ok) {
191
194
  throw data; // webrpc error response
192
195
  }
193
-
194
196
  return data;
195
197
  });
196
198
  };
@@ -201,6 +203,7 @@ class GuardSigner {
201
203
  this.address = address;
202
204
  this.url = url;
203
205
  this.appendSuffix = appendSuffix;
206
+ this.guard = void 0;
204
207
  this.guard = new Guard(url, fetch);
205
208
  }
206
209
  async getAddress() {
@@ -215,15 +218,10 @@ class GuardSigner {
215
218
  async decorateTransactions(bundle, _metadata) {
216
219
  return bundle;
217
220
  }
218
- async requestSignature(_id, message, metadata, callbacks) {
221
+ async sign(message, metadata) {
219
222
  var _metadata$parts;
220
- const {
221
- onSignature,
222
- onRejection
223
- } = callbacks;
224
223
  if (!core.commons.isWalletSignRequestMetadata(metadata)) {
225
- onRejection('expected sequence signature request metadata');
226
- return false;
224
+ throw new Error('expected sequence signature request metadata');
227
225
  }
228
226
  const guardTotpCode = metadata.guardTotpCode;
229
227
 
@@ -233,31 +231,18 @@ class GuardSigner {
233
231
  const {
234
232
  encoded
235
233
  } = coder.signature.encodeSigners(metadata.config, (_metadata$parts = metadata.parts) != null ? _metadata$parts : new Map(), [], metadata.chainId);
236
- try {
237
- const {
238
- sig: signature
239
- } = await this.guard.signWith({
240
- signer: this.address,
241
- request: {
242
- msg: ethers.ethers.utils.hexlify(message),
243
- auxData: this.packMsgAndSig(metadata.address, metadata.digest, encoded, metadata.chainId),
244
- chainId: ethers.ethers.BigNumber.from(metadata.chainId).toNumber()
245
- },
246
- token: guardTotpCode ? {
247
- id: AuthMethod.TOTP,
248
- token: guardTotpCode
249
- } : undefined
250
- });
251
- if (ethers.ethers.utils.arrayify(signature).length === 0) {
252
- throw new Error('guard response contained no signature data');
253
- }
254
- onSignature(signature);
255
- return true;
256
- } catch (error) {
257
- var _ref, _error$message;
258
- onRejection(`unable to request guard signature: ${(_ref = (_error$message = error.message) != null ? _error$message : error.msg) != null ? _ref : error}`);
259
- return false;
260
- }
234
+ return (await this.guard.signWith({
235
+ signer: this.address,
236
+ request: {
237
+ msg: ethers.ethers.utils.hexlify(message),
238
+ auxData: this.packMsgAndSig(metadata.address, metadata.digest, encoded, metadata.chainId),
239
+ chainId: ethers.ethers.BigNumber.from(metadata.chainId).toNumber()
240
+ },
241
+ token: guardTotpCode ? {
242
+ id: AuthMethod.TOTP,
243
+ token: guardTotpCode
244
+ } : undefined
245
+ })).sig;
261
246
  }
262
247
  notifyStatusChange(_id, _status, _metadata) {}
263
248
  async getAuthMethods(proof) {
@@ -411,19 +396,12 @@ async function signOwnershipProof(proof) {
411
396
  const timestamp = new Date();
412
397
  const typedData = getOwnershipProofTypedData(proof.walletAddress, timestamp);
413
398
  const digest = utils.encodeTypedDataDigest(typedData);
414
- const randomId = ethers.ethers.utils.hexlify(ethers.ethers.utils.randomBytes(32));
415
- return new Promise((resolve, reject) => signer.requestSignature(randomId, digest, {}, {
416
- onSignature(signature) {
417
- resolve({
418
- walletAddress: proof.walletAddress,
419
- timestamp,
420
- signerAddress,
421
- signature: ethers.ethers.utils.hexlify(signature)
422
- });
423
- },
424
- onRejection: reject,
425
- onStatus(_situation) {}
426
- }));
399
+ return {
400
+ walletAddress: proof.walletAddress,
401
+ timestamp,
402
+ signerAddress,
403
+ signature: ethers.ethers.utils.hexlify(await signer.sign(digest, {}))
404
+ };
427
405
  }
428
406
  }
429
407
  async function signAuthUpdateProof(proof) {
@@ -25,11 +25,14 @@ function _extends() {
25
25
  //
26
26
  // Types
27
27
  //
28
+
28
29
  //
29
30
  // Client
30
31
  //
31
32
  class Guard {
32
33
  constructor(hostname, fetch) {
34
+ this.hostname = void 0;
35
+ this.fetch = void 0;
33
36
  this.path = '/rpc/Guard/';
34
37
  this.ping = headers => {
35
38
  return this.fetch(this.url('Ping'), createHTTPRequest({}, headers)).then(res => {
@@ -190,7 +193,6 @@ const buildResponse = res => {
190
193
  if (!res.ok) {
191
194
  throw data; // webrpc error response
192
195
  }
193
-
194
196
  return data;
195
197
  });
196
198
  };
@@ -201,6 +203,7 @@ class GuardSigner {
201
203
  this.address = address;
202
204
  this.url = url;
203
205
  this.appendSuffix = appendSuffix;
206
+ this.guard = void 0;
204
207
  this.guard = new Guard(url, fetch);
205
208
  }
206
209
  async getAddress() {
@@ -215,15 +218,10 @@ class GuardSigner {
215
218
  async decorateTransactions(bundle, _metadata) {
216
219
  return bundle;
217
220
  }
218
- async requestSignature(_id, message, metadata, callbacks) {
221
+ async sign(message, metadata) {
219
222
  var _metadata$parts;
220
- const {
221
- onSignature,
222
- onRejection
223
- } = callbacks;
224
223
  if (!core.commons.isWalletSignRequestMetadata(metadata)) {
225
- onRejection('expected sequence signature request metadata');
226
- return false;
224
+ throw new Error('expected sequence signature request metadata');
227
225
  }
228
226
  const guardTotpCode = metadata.guardTotpCode;
229
227
 
@@ -233,31 +231,18 @@ class GuardSigner {
233
231
  const {
234
232
  encoded
235
233
  } = coder.signature.encodeSigners(metadata.config, (_metadata$parts = metadata.parts) != null ? _metadata$parts : new Map(), [], metadata.chainId);
236
- try {
237
- const {
238
- sig: signature
239
- } = await this.guard.signWith({
240
- signer: this.address,
241
- request: {
242
- msg: ethers.ethers.utils.hexlify(message),
243
- auxData: this.packMsgAndSig(metadata.address, metadata.digest, encoded, metadata.chainId),
244
- chainId: ethers.ethers.BigNumber.from(metadata.chainId).toNumber()
245
- },
246
- token: guardTotpCode ? {
247
- id: AuthMethod.TOTP,
248
- token: guardTotpCode
249
- } : undefined
250
- });
251
- if (ethers.ethers.utils.arrayify(signature).length === 0) {
252
- throw new Error('guard response contained no signature data');
253
- }
254
- onSignature(signature);
255
- return true;
256
- } catch (error) {
257
- var _ref, _error$message;
258
- onRejection(`unable to request guard signature: ${(_ref = (_error$message = error.message) != null ? _error$message : error.msg) != null ? _ref : error}`);
259
- return false;
260
- }
234
+ return (await this.guard.signWith({
235
+ signer: this.address,
236
+ request: {
237
+ msg: ethers.ethers.utils.hexlify(message),
238
+ auxData: this.packMsgAndSig(metadata.address, metadata.digest, encoded, metadata.chainId),
239
+ chainId: ethers.ethers.BigNumber.from(metadata.chainId).toNumber()
240
+ },
241
+ token: guardTotpCode ? {
242
+ id: AuthMethod.TOTP,
243
+ token: guardTotpCode
244
+ } : undefined
245
+ })).sig;
261
246
  }
262
247
  notifyStatusChange(_id, _status, _metadata) {}
263
248
  async getAuthMethods(proof) {
@@ -411,19 +396,12 @@ async function signOwnershipProof(proof) {
411
396
  const timestamp = new Date();
412
397
  const typedData = getOwnershipProofTypedData(proof.walletAddress, timestamp);
413
398
  const digest = utils.encodeTypedDataDigest(typedData);
414
- const randomId = ethers.ethers.utils.hexlify(ethers.ethers.utils.randomBytes(32));
415
- return new Promise((resolve, reject) => signer.requestSignature(randomId, digest, {}, {
416
- onSignature(signature) {
417
- resolve({
418
- walletAddress: proof.walletAddress,
419
- timestamp,
420
- signerAddress,
421
- signature: ethers.ethers.utils.hexlify(signature)
422
- });
423
- },
424
- onRejection: reject,
425
- onStatus(_situation) {}
426
- }));
399
+ return {
400
+ walletAddress: proof.walletAddress,
401
+ timestamp,
402
+ signerAddress,
403
+ signature: ethers.ethers.utils.hexlify(await signer.sign(digest, {}))
404
+ };
427
405
  }
428
406
  }
429
407
  async function signAuthUpdateProof(proof) {
@@ -21,11 +21,14 @@ function _extends() {
21
21
  //
22
22
  // Types
23
23
  //
24
+
24
25
  //
25
26
  // Client
26
27
  //
27
28
  class Guard {
28
29
  constructor(hostname, fetch) {
30
+ this.hostname = void 0;
31
+ this.fetch = void 0;
29
32
  this.path = '/rpc/Guard/';
30
33
  this.ping = headers => {
31
34
  return this.fetch(this.url('Ping'), createHTTPRequest({}, headers)).then(res => {
@@ -186,7 +189,6 @@ const buildResponse = res => {
186
189
  if (!res.ok) {
187
190
  throw data; // webrpc error response
188
191
  }
189
-
190
192
  return data;
191
193
  });
192
194
  };
@@ -197,6 +199,7 @@ class GuardSigner {
197
199
  this.address = address;
198
200
  this.url = url;
199
201
  this.appendSuffix = appendSuffix;
202
+ this.guard = void 0;
200
203
  this.guard = new Guard(url, fetch);
201
204
  }
202
205
  async getAddress() {
@@ -211,15 +214,10 @@ class GuardSigner {
211
214
  async decorateTransactions(bundle, _metadata) {
212
215
  return bundle;
213
216
  }
214
- async requestSignature(_id, message, metadata, callbacks) {
217
+ async sign(message, metadata) {
215
218
  var _metadata$parts;
216
- const {
217
- onSignature,
218
- onRejection
219
- } = callbacks;
220
219
  if (!commons.isWalletSignRequestMetadata(metadata)) {
221
- onRejection('expected sequence signature request metadata');
222
- return false;
220
+ throw new Error('expected sequence signature request metadata');
223
221
  }
224
222
  const guardTotpCode = metadata.guardTotpCode;
225
223
 
@@ -229,31 +227,18 @@ class GuardSigner {
229
227
  const {
230
228
  encoded
231
229
  } = coder.signature.encodeSigners(metadata.config, (_metadata$parts = metadata.parts) != null ? _metadata$parts : new Map(), [], metadata.chainId);
232
- try {
233
- const {
234
- sig: signature
235
- } = await this.guard.signWith({
236
- signer: this.address,
237
- request: {
238
- msg: ethers.utils.hexlify(message),
239
- auxData: this.packMsgAndSig(metadata.address, metadata.digest, encoded, metadata.chainId),
240
- chainId: ethers.BigNumber.from(metadata.chainId).toNumber()
241
- },
242
- token: guardTotpCode ? {
243
- id: AuthMethod.TOTP,
244
- token: guardTotpCode
245
- } : undefined
246
- });
247
- if (ethers.utils.arrayify(signature).length === 0) {
248
- throw new Error('guard response contained no signature data');
249
- }
250
- onSignature(signature);
251
- return true;
252
- } catch (error) {
253
- var _ref, _error$message;
254
- onRejection(`unable to request guard signature: ${(_ref = (_error$message = error.message) != null ? _error$message : error.msg) != null ? _ref : error}`);
255
- return false;
256
- }
230
+ return (await this.guard.signWith({
231
+ signer: this.address,
232
+ request: {
233
+ msg: ethers.utils.hexlify(message),
234
+ auxData: this.packMsgAndSig(metadata.address, metadata.digest, encoded, metadata.chainId),
235
+ chainId: ethers.BigNumber.from(metadata.chainId).toNumber()
236
+ },
237
+ token: guardTotpCode ? {
238
+ id: AuthMethod.TOTP,
239
+ token: guardTotpCode
240
+ } : undefined
241
+ })).sig;
257
242
  }
258
243
  notifyStatusChange(_id, _status, _metadata) {}
259
244
  async getAuthMethods(proof) {
@@ -407,19 +392,12 @@ async function signOwnershipProof(proof) {
407
392
  const timestamp = new Date();
408
393
  const typedData = getOwnershipProofTypedData(proof.walletAddress, timestamp);
409
394
  const digest = encodeTypedDataDigest(typedData);
410
- const randomId = ethers.utils.hexlify(ethers.utils.randomBytes(32));
411
- return new Promise((resolve, reject) => signer.requestSignature(randomId, digest, {}, {
412
- onSignature(signature) {
413
- resolve({
414
- walletAddress: proof.walletAddress,
415
- timestamp,
416
- signerAddress,
417
- signature: ethers.utils.hexlify(signature)
418
- });
419
- },
420
- onRejection: reject,
421
- onStatus(_situation) {}
422
- }));
395
+ return {
396
+ walletAddress: proof.walletAddress,
397
+ timestamp,
398
+ signerAddress,
399
+ signature: ethers.utils.hexlify(await signer.sign(digest, {}))
400
+ };
423
401
  }
424
402
  }
425
403
  async function signAuthUpdateProof(proof) {
@@ -14,11 +14,7 @@ export declare class GuardSigner implements signers.SapientSigner {
14
14
  buildDeployTransaction(_metadata: object): Promise<commons.transaction.TransactionBundle | undefined>;
15
15
  predecorateSignedTransactions(_metadata: object): Promise<commons.transaction.SignedTransactionBundle[]>;
16
16
  decorateTransactions(bundle: commons.transaction.IntendedTransactionBundle, _metadata: object): Promise<commons.transaction.IntendedTransactionBundle>;
17
- requestSignature(_id: string, message: BytesLike, metadata: object, callbacks: {
18
- onSignature: (signature: BytesLike) => void;
19
- onRejection: (error: string) => void;
20
- onStatus: (situation: string) => void;
21
- }): Promise<boolean>;
17
+ sign(message: BytesLike, metadata: object): Promise<BytesLike>;
22
18
  notifyStatusChange(_id: string, _status: Status, _metadata: object): void;
23
19
  getAuthMethods(proof: OwnershipProof): Promise<{
24
20
  methods: AuthMethod[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xsequence/guard",
3
- "version": "1.4.9",
3
+ "version": "1.6.0",
4
4
  "description": "guard sub-package for Sequence",
5
5
  "repository": "https://github.com/0xsequence/sequence.js/tree/master/packages/guard",
6
6
  "source": "src/index.ts",
@@ -10,10 +10,10 @@
10
10
  "license": "Apache-2.0",
11
11
  "dependencies": {
12
12
  "ethers": "^5.7.2",
13
- "@0xsequence/utils": "1.4.9",
14
- "@0xsequence/core": "1.4.9",
15
- "@0xsequence/account": "1.4.9",
16
- "@0xsequence/signhub": "1.4.9"
13
+ "@0xsequence/account": "1.6.0",
14
+ "@0xsequence/core": "1.6.0",
15
+ "@0xsequence/signhub": "1.6.0",
16
+ "@0xsequence/utils": "1.6.0"
17
17
  },
18
18
  "files": [
19
19
  "src",
package/src/signer.ts CHANGED
@@ -37,21 +37,9 @@ export class GuardSigner implements signers.SapientSigner {
37
37
  return bundle
38
38
  }
39
39
 
40
- async requestSignature(
41
- _id: string,
42
- message: BytesLike,
43
- metadata: object,
44
- callbacks: {
45
- onSignature: (signature: BytesLike) => void
46
- onRejection: (error: string) => void
47
- onStatus: (situation: string) => void
48
- }
49
- ): Promise<boolean> {
50
- const { onSignature, onRejection } = callbacks
51
-
40
+ async sign(message: BytesLike, metadata: object): Promise<BytesLike> {
52
41
  if (!commons.isWalletSignRequestMetadata(metadata)) {
53
- onRejection('expected sequence signature request metadata')
54
- return false
42
+ throw new Error('expected sequence signature request metadata')
55
43
  }
56
44
 
57
45
  const guardTotpCode = (metadata as { guardTotpCode?: string }).guardTotpCode
@@ -61,8 +49,8 @@ export class GuardSigner implements signers.SapientSigner {
61
49
  const coder = universal.genericCoderFor(metadata.config.version)
62
50
  const { encoded } = coder.signature.encodeSigners(metadata.config, metadata.parts ?? new Map(), [], metadata.chainId)
63
51
 
64
- try {
65
- const { sig: signature } = await this.guard.signWith({
52
+ return (
53
+ await this.guard.signWith({
66
54
  signer: this.address,
67
55
  request: {
68
56
  msg: ethers.utils.hexlify(message),
@@ -71,17 +59,7 @@ export class GuardSigner implements signers.SapientSigner {
71
59
  },
72
60
  token: guardTotpCode ? { id: AuthMethod.TOTP, token: guardTotpCode } : undefined
73
61
  })
74
-
75
- if (ethers.utils.arrayify(signature).length === 0) {
76
- throw new Error('guard response contained no signature data')
77
- }
78
-
79
- onSignature(signature)
80
- return true
81
- } catch (error) {
82
- onRejection(`unable to request guard signature: ${error.message ?? error.msg ?? error}`)
83
- return false
84
- }
62
+ ).sig
85
63
  }
86
64
 
87
65
  notifyStatusChange(_id: string, _status: Status, _metadata: object): void {}
@@ -248,27 +226,13 @@ async function signOwnershipProof(
248
226
  const timestamp = new Date()
249
227
  const typedData = getOwnershipProofTypedData(proof.walletAddress, timestamp)
250
228
  const digest = encodeTypedDataDigest(typedData)
251
- const randomId = ethers.utils.hexlify(ethers.utils.randomBytes(32))
252
-
253
- return new Promise((resolve, reject) =>
254
- signer.requestSignature(
255
- randomId,
256
- digest,
257
- {},
258
- {
259
- onSignature(signature) {
260
- resolve({
261
- walletAddress: proof.walletAddress,
262
- timestamp,
263
- signerAddress,
264
- signature: ethers.utils.hexlify(signature)
265
- })
266
- },
267
- onRejection: reject,
268
- onStatus(_situation) {}
269
- }
270
- )
271
- )
229
+
230
+ return {
231
+ walletAddress: proof.walletAddress,
232
+ timestamp,
233
+ signerAddress,
234
+ signature: ethers.utils.hexlify(await signer.sign(digest, {}))
235
+ }
272
236
  }
273
237
  }
274
238