@0xsequence/guard 1.4.0 → 1.4.2

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.
@@ -1,5 +1,7 @@
1
- import { ethers } from 'ethers';
2
1
  import { commons, universal } from '@0xsequence/core';
2
+ import { signers } from '@0xsequence/signhub';
3
+ import { encodeTypedDataDigest } from '@0xsequence/utils';
4
+ import { ethers } from 'ethers';
3
5
 
4
6
  function _extends() {
5
7
  _extends = Object.assign ? Object.assign.bind() : function (target) {
@@ -16,22 +18,6 @@ function _extends() {
16
18
  return _extends.apply(this, arguments);
17
19
  }
18
20
 
19
- /* eslint-disable */
20
- // sequence-guard v0.4.0 a29651d1d5f63268e8d03b51e46557e0632c144d
21
- // --
22
- // Code generated by webrpc-gen@v0.10.x-dev with typescript generator. DO NOT EDIT.
23
- //
24
- // webrpc-gen -schema=guard.ridl -target=typescript -client -out=./clients/guard.gen.ts
25
-
26
- // WebRPC description and code-gen version
27
- const WebRPCVersion = 'v1';
28
-
29
- // Schema version of your RIDL schema
30
- const WebRPCSchemaVersion = 'v0.4.0';
31
-
32
- // Schema hash generated from your RIDL schema
33
- const WebRPCSchemaHash = 'a29651d1d5f63268e8d03b51e46557e0632c144d';
34
-
35
21
  //
36
22
  // Types
37
23
  //
@@ -95,6 +81,80 @@ class Guard {
95
81
  });
96
82
  });
97
83
  };
84
+ this.authMethods = (args, headers) => {
85
+ return this.fetch(this.url('AuthMethods'), createHTTPRequest(args, headers)).then(res => {
86
+ return buildResponse(res).then(_data => {
87
+ return {
88
+ methods: _data.methods,
89
+ active: _data.active
90
+ };
91
+ });
92
+ });
93
+ };
94
+ this.setPIN = (args, headers) => {
95
+ return this.fetch(this.url('SetPIN'), createHTTPRequest(args, headers)).then(res => {
96
+ return buildResponse(res).then(_data => {
97
+ return {};
98
+ });
99
+ });
100
+ };
101
+ this.resetPIN = (args, headers) => {
102
+ return this.fetch(this.url('ResetPIN'), createHTTPRequest(args, headers)).then(res => {
103
+ return buildResponse(res).then(_data => {
104
+ return {};
105
+ });
106
+ });
107
+ };
108
+ this.createTOTP = (args, headers) => {
109
+ return this.fetch(this.url('CreateTOTP'), createHTTPRequest(args, headers)).then(res => {
110
+ return buildResponse(res).then(_data => {
111
+ return {
112
+ uri: _data.uri
113
+ };
114
+ });
115
+ });
116
+ };
117
+ this.commitTOTP = (args, headers) => {
118
+ return this.fetch(this.url('CommitTOTP'), createHTTPRequest(args, headers)).then(res => {
119
+ return buildResponse(res).then(_data => {
120
+ return {
121
+ codes: _data.codes
122
+ };
123
+ });
124
+ });
125
+ };
126
+ this.resetTOTP = (args, headers) => {
127
+ return this.fetch(this.url('ResetTOTP'), createHTTPRequest(args, headers)).then(res => {
128
+ return buildResponse(res).then(_data => {
129
+ return {};
130
+ });
131
+ });
132
+ };
133
+ this.reset2FA = (args, headers) => {
134
+ return this.fetch(this.url('Reset2FA'), createHTTPRequest(args, headers)).then(res => {
135
+ return buildResponse(res).then(_data => {
136
+ return {};
137
+ });
138
+ });
139
+ };
140
+ this.recoveryCodes = (args, headers) => {
141
+ return this.fetch(this.url('RecoveryCodes'), createHTTPRequest(args, headers)).then(res => {
142
+ return buildResponse(res).then(_data => {
143
+ return {
144
+ codes: _data.codes
145
+ };
146
+ });
147
+ });
148
+ };
149
+ this.resetRecoveryCodes = (args, headers) => {
150
+ return this.fetch(this.url('ResetRecoveryCodes'), createHTTPRequest(args, headers)).then(res => {
151
+ return buildResponse(res).then(_data => {
152
+ return {
153
+ codes: _data.codes
154
+ };
155
+ });
156
+ });
157
+ };
98
158
  this.hostname = hostname;
99
159
  this.fetch = (input, init) => fetch(input, init);
100
160
  }
@@ -133,12 +193,10 @@ const buildResponse = res => {
133
193
 
134
194
  const fetch = typeof global === 'object' ? global.fetch : window.fetch;
135
195
  class GuardSigner {
136
- constructor(address, url, appendSuffix = false, onError) {
137
- this.requests = new Map();
196
+ constructor(address, url, appendSuffix = false) {
138
197
  this.address = address;
139
198
  this.url = url;
140
199
  this.appendSuffix = appendSuffix;
141
- this.onError = onError;
142
200
  this.guard = new Guard(url, fetch);
143
201
  }
144
202
  async getAddress() {
@@ -153,32 +211,18 @@ class GuardSigner {
153
211
  async decorateTransactions(bundle, _metadata) {
154
212
  return bundle;
155
213
  }
156
- async requestSignature(id, _message, metadata, callbacks) {
157
- if (!commons.isWalletSignRequestMetadata(metadata)) {
158
- callbacks.onRejection('Expected Sequence-like metadata');
159
- } else {
160
- // Queue the request first, this method only does that
161
- // the requesting to the API is later handled on every status change
162
- this.requests.set(id, callbacks);
163
- }
164
- return true;
165
- }
166
- notifyStatusChange(id, status, metadata) {
167
- if (!this.requests.has(id)) return;
214
+ async requestSignature(_id, message, metadata, callbacks) {
215
+ var _metadata$parts;
216
+ const {
217
+ onSignature,
218
+ onRejection
219
+ } = callbacks;
168
220
  if (!commons.isWalletSignRequestMetadata(metadata)) {
169
- this.requests.get(id).onRejection('Expected Sequence-like metadata (status update)');
170
- return;
221
+ onRejection('expected sequence signature request metadata');
222
+ return false;
171
223
  }
172
- this.evaluateRequest(id, status.message, status, metadata);
173
- }
174
- packMsgAndSig(address, msg, sig, chainId) {
175
- return ethers.utils.defaultAbiCoder.encode(['address', 'uint256', 'bytes', 'bytes'], [address, chainId, msg, sig]);
176
- }
177
- keyOfRequest(signer, msg, auxData, chainId) {
178
- return ethers.utils.solidityKeccak256(['address', 'uint256', 'bytes', 'bytes'], [signer, chainId, msg, auxData]);
179
- }
180
- async evaluateRequest(id, message, _, metadata) {
181
- var _metadata$parts;
224
+ const guardTotpCode = metadata.guardTotpCode;
225
+
182
226
  // Building auxData, notice: this uses the old v1 format
183
227
  // TODO: We should update the guard API so we can pass the metadata directly
184
228
  const coder = universal.genericCoderFor(metadata.config.version);
@@ -186,37 +230,250 @@ class GuardSigner {
186
230
  encoded
187
231
  } = coder.signature.encodeSigners(metadata.config, (_metadata$parts = metadata.parts) != null ? _metadata$parts : new Map(), [], metadata.chainId);
188
232
  try {
189
- var _this$requests$get;
190
- const key = this.keyOfRequest(this.address, message, encoded, metadata.chainId);
191
- const lastAttempt = (_this$requests$get = this.requests.get(id)) == null ? void 0 : _this$requests$get.lastAttempt;
192
- if (lastAttempt === key) {
193
- return;
194
- }
195
- this.requests.get(id).lastAttempt = key;
196
- const result = await this.guard.signWith({
233
+ const {
234
+ sig: signature
235
+ } = await this.guard.signWith({
197
236
  signer: this.address,
198
237
  request: {
199
238
  msg: ethers.utils.hexlify(message),
200
239
  auxData: this.packMsgAndSig(metadata.address, metadata.digest, encoded, metadata.chainId),
201
- chainId: ethers.BigNumber.from(metadata.chainId).toNumber() // TODO: This should be a string (in the API)
202
- }
240
+ chainId: ethers.BigNumber.from(metadata.chainId).toNumber()
241
+ },
242
+ token: guardTotpCode ? {
243
+ id: AuthMethod.TOTP,
244
+ token: guardTotpCode
245
+ } : undefined
203
246
  });
204
-
205
- if (ethers.utils.arrayify(result.sig).length !== 0) {
206
- this.requests.get(id).onSignature(result.sig);
207
- this.requests.delete(id);
247
+ if (ethers.utils.arrayify(signature).length === 0) {
248
+ throw new Error('guard response contained no signature data');
208
249
  }
209
- } catch (e) {
210
- var _this$onError;
211
- // The guard signer may reject the request for a number of reasons
212
- // like for example, if it's being the first signer (it waits for other signers to sign first)
213
- // We always forward the error here and filter on client side.
214
- (_this$onError = this.onError) == null ? void 0 : _this$onError.call(this, e);
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
+ }
257
+ }
258
+ notifyStatusChange(_id, _status, _metadata) {}
259
+ async getAuthMethods(proof) {
260
+ let response;
261
+ if ('jwt' in proof) {
262
+ response = await this.guard.authMethods({}, {
263
+ Authorization: `BEARER ${proof.jwt}`
264
+ });
265
+ } else {
266
+ const signedProof = await signOwnershipProof(proof);
267
+ response = await this.guard.authMethods({
268
+ proof: {
269
+ wallet: signedProof.walletAddress,
270
+ timestamp: signedProof.timestamp.getTime(),
271
+ signer: signedProof.signerAddress,
272
+ signature: signedProof.signature
273
+ }
274
+ });
275
+ }
276
+ return response.methods.map(parseAuthMethod);
277
+ }
278
+ async setPin(pin, proof) {
279
+ const signedProof = await signAuthUpdateProof(proof);
280
+ if (pin === undefined) {
281
+ await this.guard.resetPIN({
282
+ timestamp: signedProof.timestamp.getTime(),
283
+ signature: signedProof.signature
284
+ }, {
285
+ Authorization: `BEARER ${proof.jwt}`
286
+ });
287
+ } else {
288
+ await this.guard.setPIN({
289
+ pin,
290
+ timestamp: signedProof.timestamp.getTime(),
291
+ signature: signedProof.signature
292
+ }, {
293
+ Authorization: `BEARER ${proof.jwt}`
294
+ });
215
295
  }
216
296
  }
297
+ resetPin(proof) {
298
+ return this.setPin(undefined, proof);
299
+ }
300
+ async createTotp(proof) {
301
+ const signedProof = await signAuthUpdateProof(proof);
302
+ const {
303
+ uri
304
+ } = await this.guard.createTOTP({
305
+ timestamp: signedProof.timestamp.getTime(),
306
+ signature: signedProof.signature
307
+ }, {
308
+ Authorization: `BEARER ${proof.jwt}`
309
+ });
310
+ return new URL(uri);
311
+ }
312
+ async commitTotp(token, jwt) {
313
+ const {
314
+ codes
315
+ } = await this.guard.commitTOTP({
316
+ token
317
+ }, {
318
+ Authorization: `BEARER ${jwt}`
319
+ });
320
+ return codes;
321
+ }
322
+ async resetTotp(proof) {
323
+ const signedProof = await signAuthUpdateProof(proof);
324
+ await this.guard.resetTOTP({
325
+ timestamp: signedProof.timestamp.getTime(),
326
+ signature: signedProof.signature
327
+ }, {
328
+ Authorization: `BEARER ${proof.jwt}`
329
+ });
330
+ }
331
+ async reset2fa(recoveryCode, proof) {
332
+ if ('jwt' in proof) {
333
+ await this.guard.reset2FA({
334
+ code: recoveryCode
335
+ }, {
336
+ Authorization: `BEARER ${proof.jwt}`
337
+ });
338
+ } else {
339
+ const signedProof = await signOwnershipProof(proof);
340
+ await this.guard.reset2FA({
341
+ code: recoveryCode,
342
+ proof: {
343
+ wallet: signedProof.walletAddress,
344
+ timestamp: signedProof.timestamp.getTime(),
345
+ signer: signedProof.signerAddress,
346
+ signature: signedProof.signature
347
+ }
348
+ });
349
+ }
350
+ }
351
+ async getRecoveryCodes(proof) {
352
+ const signedProof = await signAuthUpdateProof(proof);
353
+ const {
354
+ codes
355
+ } = await this.guard.recoveryCodes({
356
+ timestamp: signedProof.timestamp.getTime(),
357
+ signature: signedProof.signature
358
+ }, {
359
+ Authorization: `BEARER ${proof.jwt}`
360
+ });
361
+ return codes;
362
+ }
363
+ async resetRecoveryCodes(proof) {
364
+ const signedProof = await signAuthUpdateProof(proof);
365
+ const {
366
+ codes
367
+ } = await this.guard.resetRecoveryCodes({
368
+ timestamp: signedProof.timestamp.getTime(),
369
+ signature: signedProof.signature
370
+ }, {
371
+ Authorization: `BEARER ${proof.jwt}`
372
+ });
373
+ return codes;
374
+ }
375
+ packMsgAndSig(address, msg, sig, chainId) {
376
+ return ethers.utils.defaultAbiCoder.encode(['address', 'uint256', 'bytes', 'bytes'], [address, chainId, msg, sig]);
377
+ }
217
378
  suffix() {
218
379
  return this.appendSuffix ? [3] : [];
219
380
  }
220
381
  }
382
+ let AuthMethod = /*#__PURE__*/function (AuthMethod) {
383
+ AuthMethod["PIN"] = "PIN";
384
+ AuthMethod["TOTP"] = "TOTP";
385
+ return AuthMethod;
386
+ }({});
387
+ function parseAuthMethod(method) {
388
+ switch (method) {
389
+ case AuthMethod.PIN:
390
+ case AuthMethod.TOTP:
391
+ return method;
392
+ default:
393
+ throw new Error(`unknown auth method '${method}'`);
394
+ }
395
+ }
396
+ function isSignedOwnershipProof(proof) {
397
+ return 'signerAddress' in proof && typeof proof.signerAddress === 'string';
398
+ }
399
+ async function signOwnershipProof(proof) {
400
+ if (isSignedOwnershipProof(proof)) {
401
+ return proof;
402
+ } else {
403
+ const signer = signers.isSapientSigner(proof.signer) ? proof.signer : new signers.SignerWrapper(proof.signer);
404
+ const signerAddress = await signer.getAddress();
405
+ const timestamp = new Date();
406
+ const typedData = getOwnershipProofTypedData(proof.walletAddress, timestamp);
407
+ const digest = encodeTypedDataDigest(typedData);
408
+ const randomId = ethers.utils.hexlify(ethers.utils.randomBytes(32));
409
+ return new Promise((resolve, reject) => signer.requestSignature(randomId, digest, {}, {
410
+ onSignature(signature) {
411
+ resolve({
412
+ walletAddress: proof.walletAddress,
413
+ timestamp,
414
+ signerAddress,
415
+ signature: ethers.utils.hexlify(signature)
416
+ });
417
+ },
418
+ onRejection: reject,
419
+ onStatus(_situation) {}
420
+ }));
421
+ }
422
+ }
423
+ async function signAuthUpdateProof(proof) {
424
+ if ('wallet' in proof) {
425
+ var _typedData$domain$cha;
426
+ const timestamp = new Date();
427
+ const typedData = getAuthUpdateProofTypedData(timestamp);
428
+ const signature = await proof.wallet.signTypedData(typedData.domain, typedData.types, typedData.message, (_typedData$domain$cha = typedData.domain.chainId) != null ? _typedData$domain$cha : 1, 'eip6492');
429
+ return {
430
+ jwt: proof.jwt,
431
+ timestamp,
432
+ signature
433
+ };
434
+ } else {
435
+ return proof;
436
+ }
437
+ }
438
+ function getOwnershipProofTypedData(wallet, timestamp) {
439
+ return {
440
+ domain,
441
+ types: {
442
+ AuthMethods: [{
443
+ name: 'wallet',
444
+ type: 'address'
445
+ }, {
446
+ name: 'timestamp',
447
+ type: 'string'
448
+ }]
449
+ },
450
+ message: {
451
+ wallet: ethers.utils.getAddress(wallet),
452
+ timestamp: toUTCString(timestamp)
453
+ }
454
+ };
455
+ }
456
+ function getAuthUpdateProofTypedData(timestamp) {
457
+ return {
458
+ domain,
459
+ types: {
460
+ AuthUpdate: [{
461
+ name: 'timestamp',
462
+ type: 'string'
463
+ }]
464
+ },
465
+ message: {
466
+ timestamp: toUTCString(timestamp)
467
+ }
468
+ };
469
+ }
470
+ const domain = {
471
+ name: 'Sequence Guard',
472
+ version: '1',
473
+ chainId: 1
474
+ };
475
+ function toUTCString(date) {
476
+ return date.toUTCString().replace('GMT', 'UTC');
477
+ }
221
478
 
222
- export { Guard, GuardSigner, WebRPCSchemaHash, WebRPCSchemaVersion, WebRPCVersion };
479
+ export { AuthMethod, GuardSigner, getAuthUpdateProofTypedData, getOwnershipProofTypedData };
@@ -1,6 +1,6 @@
1
1
  export declare const WebRPCVersion = "v1";
2
2
  export declare const WebRPCSchemaVersion = "v0.4.0";
3
- export declare const WebRPCSchemaHash = "a29651d1d5f63268e8d03b51e46557e0632c144d";
3
+ export declare const WebRPCSchemaHash = "2e5d6a4c9b797598078365d7439f330bc7bbf29c";
4
4
  export interface Version {
5
5
  webrpcVersion: string;
6
6
  schemaVersion: string;
@@ -28,6 +28,20 @@ export interface SignRequest {
28
28
  msg: string;
29
29
  auxData: string;
30
30
  }
31
+ export interface OwnershipProof {
32
+ wallet: string;
33
+ timestamp: number;
34
+ signer: string;
35
+ signature: string;
36
+ }
37
+ export interface AuthToken {
38
+ id: string;
39
+ token: string;
40
+ }
41
+ export interface RecoveryCode {
42
+ code: string;
43
+ used: boolean;
44
+ }
31
45
  export interface Guard {
32
46
  ping(headers?: object): Promise<PingReturn>;
33
47
  version(headers?: object): Promise<VersionReturn>;
@@ -35,6 +49,15 @@ export interface Guard {
35
49
  getSignerConfig(args: GetSignerConfigArgs, headers?: object): Promise<GetSignerConfigReturn>;
36
50
  sign(args: SignArgs, headers?: object): Promise<SignReturn>;
37
51
  signWith(args: SignWithArgs, headers?: object): Promise<SignWithReturn>;
52
+ authMethods(args: AuthMethodsArgs, headers?: object): Promise<AuthMethodsReturn>;
53
+ setPIN(args: SetPINArgs, headers?: object): Promise<SetPINReturn>;
54
+ resetPIN(args: ResetPINArgs, headers?: object): Promise<ResetPINReturn>;
55
+ createTOTP(args: CreateTOTPArgs, headers?: object): Promise<CreateTOTPReturn>;
56
+ commitTOTP(args: CommitTOTPArgs, headers?: object): Promise<CommitTOTPReturn>;
57
+ resetTOTP(args: ResetTOTPArgs, headers?: object): Promise<ResetTOTPReturn>;
58
+ reset2FA(args: Reset2FAArgs, headers?: object): Promise<Reset2FAReturn>;
59
+ recoveryCodes(args: RecoveryCodesArgs, headers?: object): Promise<RecoveryCodesReturn>;
60
+ resetRecoveryCodes(args: ResetRecoveryCodesArgs, headers?: object): Promise<ResetRecoveryCodesReturn>;
38
61
  }
39
62
  export interface PingArgs {
40
63
  }
@@ -59,6 +82,7 @@ export interface GetSignerConfigReturn {
59
82
  }
60
83
  export interface SignArgs {
61
84
  request: SignRequest;
85
+ token?: AuthToken;
62
86
  }
63
87
  export interface SignReturn {
64
88
  sig: string;
@@ -66,10 +90,70 @@ export interface SignReturn {
66
90
  export interface SignWithArgs {
67
91
  signer: string;
68
92
  request: SignRequest;
93
+ token?: AuthToken;
69
94
  }
70
95
  export interface SignWithReturn {
71
96
  sig: string;
72
97
  }
98
+ export interface AuthMethodsArgs {
99
+ proof?: OwnershipProof;
100
+ }
101
+ export interface AuthMethodsReturn {
102
+ methods: Array<string>;
103
+ active: boolean;
104
+ }
105
+ export interface SetPINArgs {
106
+ pin: string;
107
+ timestamp: number;
108
+ signature: string;
109
+ }
110
+ export interface SetPINReturn {
111
+ }
112
+ export interface ResetPINArgs {
113
+ timestamp: number;
114
+ signature: string;
115
+ }
116
+ export interface ResetPINReturn {
117
+ }
118
+ export interface CreateTOTPArgs {
119
+ timestamp: number;
120
+ signature: string;
121
+ }
122
+ export interface CreateTOTPReturn {
123
+ uri: string;
124
+ }
125
+ export interface CommitTOTPArgs {
126
+ token: string;
127
+ }
128
+ export interface CommitTOTPReturn {
129
+ codes: Array<RecoveryCode>;
130
+ }
131
+ export interface ResetTOTPArgs {
132
+ timestamp: number;
133
+ signature: string;
134
+ }
135
+ export interface ResetTOTPReturn {
136
+ }
137
+ export interface Reset2FAArgs {
138
+ code: string;
139
+ proof?: OwnershipProof;
140
+ }
141
+ export interface Reset2FAReturn {
142
+ }
143
+ export interface RecoveryCodesArgs {
144
+ timestamp: number;
145
+ signature: string;
146
+ }
147
+ export interface RecoveryCodesReturn {
148
+ codes: Array<RecoveryCode>;
149
+ }
150
+ export interface ResetRecoveryCodesArgs {
151
+ timestamp: number;
152
+ signature: string;
153
+ }
154
+ export interface ResetRecoveryCodesReturn {
155
+ codes: Array<RecoveryCode>;
156
+ }
73
157
  export declare class Guard implements Guard {
74
158
  protected hostname: string;
75
159
  protected fetch: Fetch;
@@ -82,6 +166,15 @@ export declare class Guard implements Guard {
82
166
  getSignerConfig: (args: GetSignerConfigArgs, headers?: object | undefined) => Promise<GetSignerConfigReturn>;
83
167
  sign: (args: SignArgs, headers?: object | undefined) => Promise<SignReturn>;
84
168
  signWith: (args: SignWithArgs, headers?: object | undefined) => Promise<SignWithReturn>;
169
+ authMethods: (args: AuthMethodsArgs, headers?: object | undefined) => Promise<AuthMethodsReturn>;
170
+ setPIN: (args: SetPINArgs, headers?: object | undefined) => Promise<SetPINReturn>;
171
+ resetPIN: (args: ResetPINArgs, headers?: object | undefined) => Promise<ResetPINReturn>;
172
+ createTOTP: (args: CreateTOTPArgs, headers?: object | undefined) => Promise<CreateTOTPReturn>;
173
+ commitTOTP: (args: CommitTOTPArgs, headers?: object | undefined) => Promise<CommitTOTPReturn>;
174
+ resetTOTP: (args: ResetTOTPArgs, headers?: object | undefined) => Promise<ResetTOTPReturn>;
175
+ reset2FA: (args: Reset2FAArgs, headers?: object | undefined) => Promise<Reset2FAReturn>;
176
+ recoveryCodes: (args: RecoveryCodesArgs, headers?: object | undefined) => Promise<RecoveryCodesReturn>;
177
+ resetRecoveryCodes: (args: ResetRecoveryCodesArgs, headers?: object | undefined) => Promise<ResetRecoveryCodesReturn>;
85
178
  }
86
179
  export interface WebRPCError extends Error {
87
180
  code: string;
@@ -1,2 +1 @@
1
- export * from "./guard.gen.js";
2
1
  export * from "./signer.js";
@@ -1,26 +1,60 @@
1
- import { signers, Status } from '@0xsequence/signhub';
2
- import { BytesLike } from 'ethers';
1
+ import { Account } from '@0xsequence/account';
3
2
  import { commons } from '@0xsequence/core';
3
+ import { signers, Status } from '@0xsequence/signhub';
4
+ import { TypedData } from '@0xsequence/utils';
5
+ import { BytesLike, ethers } from 'ethers';
6
+ import { RecoveryCode as GuardRecoveryCode } from "./guard.gen.js";
4
7
  export declare class GuardSigner implements signers.SapientSigner {
5
8
  readonly address: string;
6
9
  readonly url: string;
7
10
  readonly appendSuffix: boolean;
8
- private readonly onError?;
9
11
  private guard;
10
- private requests;
11
- constructor(address: string, url: string, appendSuffix?: boolean, onError?: ((err: Error) => void) | undefined);
12
+ constructor(address: string, url: string, appendSuffix?: boolean);
12
13
  getAddress(): Promise<string>;
13
14
  buildDeployTransaction(_metadata: object): Promise<commons.transaction.TransactionBundle | undefined>;
14
15
  predecorateSignedTransactions(_metadata: object): Promise<commons.transaction.SignedTransactionBundle[]>;
15
16
  decorateTransactions(bundle: commons.transaction.IntendedTransactionBundle, _metadata: object): Promise<commons.transaction.IntendedTransactionBundle>;
16
- requestSignature(id: string, _message: BytesLike, metadata: object, callbacks: {
17
+ requestSignature(_id: string, message: BytesLike, metadata: object, callbacks: {
17
18
  onSignature: (signature: BytesLike) => void;
18
19
  onRejection: (error: string) => void;
19
20
  onStatus: (situation: string) => void;
20
21
  }): Promise<boolean>;
21
- notifyStatusChange(id: string, status: Status, metadata: object): void;
22
+ notifyStatusChange(_id: string, _status: Status, _metadata: object): void;
23
+ getAuthMethods(proof: OwnershipProof): Promise<AuthMethod[]>;
24
+ setPin(pin: string | undefined, proof: AuthUpdateProof): Promise<void>;
25
+ resetPin(proof: AuthUpdateProof): Promise<void>;
26
+ createTotp(proof: AuthUpdateProof): Promise<URL>;
27
+ commitTotp(token: string, jwt: string): Promise<RecoveryCode[]>;
28
+ resetTotp(proof: AuthUpdateProof): Promise<void>;
29
+ reset2fa(recoveryCode: string, proof: OwnershipProof): Promise<void>;
30
+ getRecoveryCodes(proof: AuthUpdateProof): Promise<RecoveryCode[]>;
31
+ resetRecoveryCodes(proof: AuthUpdateProof): Promise<RecoveryCode[]>;
22
32
  private packMsgAndSig;
23
- private keyOfRequest;
24
- private evaluateRequest;
25
33
  suffix(): BytesLike;
26
34
  }
35
+ export type RecoveryCode = GuardRecoveryCode;
36
+ export declare enum AuthMethod {
37
+ PIN = "PIN",
38
+ TOTP = "TOTP"
39
+ }
40
+ export type OwnershipProof = {
41
+ jwt: string;
42
+ } | {
43
+ walletAddress: string;
44
+ timestamp: Date;
45
+ signerAddress: string;
46
+ signature: string;
47
+ } | {
48
+ walletAddress: string;
49
+ signer: ethers.Signer | signers.SapientSigner;
50
+ };
51
+ export type AuthUpdateProof = {
52
+ jwt: string;
53
+ } & ({
54
+ timestamp: Date;
55
+ signature: string;
56
+ } | {
57
+ wallet: Account;
58
+ });
59
+ export declare function getOwnershipProofTypedData(wallet: string, timestamp: Date): TypedData;
60
+ export declare function getAuthUpdateProofTypedData(timestamp: Date): TypedData;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xsequence/guard",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
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,8 +10,10 @@
10
10
  "license": "Apache-2.0",
11
11
  "dependencies": {
12
12
  "ethers": "^5.7.2",
13
- "@0xsequence/core": "1.4.0",
14
- "@0xsequence/signhub": "1.4.0"
13
+ "@0xsequence/account": "1.4.2",
14
+ "@0xsequence/core": "1.4.2",
15
+ "@0xsequence/signhub": "1.4.2",
16
+ "@0xsequence/utils": "1.4.2"
15
17
  },
16
18
  "files": [
17
19
  "src",