@0xsequence/guard 1.4.0 → 1.4.1

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,79 @@ 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
+ };
90
+ });
91
+ });
92
+ };
93
+ this.setPIN = (args, headers) => {
94
+ return this.fetch(this.url('SetPIN'), createHTTPRequest(args, headers)).then(res => {
95
+ return buildResponse(res).then(_data => {
96
+ return {};
97
+ });
98
+ });
99
+ };
100
+ this.resetPIN = (args, headers) => {
101
+ return this.fetch(this.url('ResetPIN'), createHTTPRequest(args, headers)).then(res => {
102
+ return buildResponse(res).then(_data => {
103
+ return {};
104
+ });
105
+ });
106
+ };
107
+ this.createTOTP = (args, headers) => {
108
+ return this.fetch(this.url('CreateTOTP'), createHTTPRequest(args, headers)).then(res => {
109
+ return buildResponse(res).then(_data => {
110
+ return {
111
+ uri: _data.uri
112
+ };
113
+ });
114
+ });
115
+ };
116
+ this.commitTOTP = (args, headers) => {
117
+ return this.fetch(this.url('CommitTOTP'), createHTTPRequest(args, headers)).then(res => {
118
+ return buildResponse(res).then(_data => {
119
+ return {
120
+ codes: _data.codes
121
+ };
122
+ });
123
+ });
124
+ };
125
+ this.resetTOTP = (args, headers) => {
126
+ return this.fetch(this.url('ResetTOTP'), createHTTPRequest(args, headers)).then(res => {
127
+ return buildResponse(res).then(_data => {
128
+ return {};
129
+ });
130
+ });
131
+ };
132
+ this.reset2FA = (args, headers) => {
133
+ return this.fetch(this.url('Reset2FA'), createHTTPRequest(args, headers)).then(res => {
134
+ return buildResponse(res).then(_data => {
135
+ return {};
136
+ });
137
+ });
138
+ };
139
+ this.recoveryCodes = (args, headers) => {
140
+ return this.fetch(this.url('RecoveryCodes'), createHTTPRequest(args, headers)).then(res => {
141
+ return buildResponse(res).then(_data => {
142
+ return {
143
+ codes: _data.codes
144
+ };
145
+ });
146
+ });
147
+ };
148
+ this.resetRecoveryCodes = (args, headers) => {
149
+ return this.fetch(this.url('ResetRecoveryCodes'), createHTTPRequest(args, headers)).then(res => {
150
+ return buildResponse(res).then(_data => {
151
+ return {
152
+ codes: _data.codes
153
+ };
154
+ });
155
+ });
156
+ };
98
157
  this.hostname = hostname;
99
158
  this.fetch = (input, init) => fetch(input, init);
100
159
  }
@@ -133,12 +192,10 @@ const buildResponse = res => {
133
192
 
134
193
  const fetch = typeof global === 'object' ? global.fetch : window.fetch;
135
194
  class GuardSigner {
136
- constructor(address, url, appendSuffix = false, onError) {
137
- this.requests = new Map();
195
+ constructor(address, url, appendSuffix = false) {
138
196
  this.address = address;
139
197
  this.url = url;
140
198
  this.appendSuffix = appendSuffix;
141
- this.onError = onError;
142
199
  this.guard = new Guard(url, fetch);
143
200
  }
144
201
  async getAddress() {
@@ -153,32 +210,18 @@ class GuardSigner {
153
210
  async decorateTransactions(bundle, _metadata) {
154
211
  return bundle;
155
212
  }
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;
213
+ async requestSignature(_id, message, metadata, callbacks) {
214
+ var _metadata$parts;
215
+ const {
216
+ onSignature,
217
+ onRejection
218
+ } = callbacks;
168
219
  if (!commons.isWalletSignRequestMetadata(metadata)) {
169
- this.requests.get(id).onRejection('Expected Sequence-like metadata (status update)');
170
- return;
220
+ onRejection('expected sequence signature request metadata');
221
+ return false;
171
222
  }
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;
223
+ const guardTotpCode = metadata.guardTotpCode;
224
+
182
225
  // Building auxData, notice: this uses the old v1 format
183
226
  // TODO: We should update the guard API so we can pass the metadata directly
184
227
  const coder = universal.genericCoderFor(metadata.config.version);
@@ -186,37 +229,250 @@ class GuardSigner {
186
229
  encoded
187
230
  } = coder.signature.encodeSigners(metadata.config, (_metadata$parts = metadata.parts) != null ? _metadata$parts : new Map(), [], metadata.chainId);
188
231
  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({
232
+ const {
233
+ sig: signature
234
+ } = await this.guard.signWith({
197
235
  signer: this.address,
198
236
  request: {
199
237
  msg: ethers.utils.hexlify(message),
200
238
  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
- }
239
+ chainId: ethers.BigNumber.from(metadata.chainId).toNumber()
240
+ },
241
+ token: guardTotpCode ? {
242
+ id: AuthMethod.TOTP,
243
+ token: guardTotpCode
244
+ } : undefined
203
245
  });
204
-
205
- if (ethers.utils.arrayify(result.sig).length !== 0) {
206
- this.requests.get(id).onSignature(result.sig);
207
- this.requests.delete(id);
246
+ if (ethers.utils.arrayify(signature).length === 0) {
247
+ throw new Error('guard response contained no signature data');
208
248
  }
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);
249
+ onSignature(signature);
250
+ return true;
251
+ } catch (error) {
252
+ var _ref, _error$message;
253
+ onRejection(`unable to request guard signature: ${(_ref = (_error$message = error.message) != null ? _error$message : error.msg) != null ? _ref : error}`);
254
+ return false;
255
+ }
256
+ }
257
+ notifyStatusChange(_id, _status, _metadata) {}
258
+ async getAuthMethods(proof) {
259
+ let response;
260
+ if ('jwt' in proof) {
261
+ response = await this.guard.authMethods({}, {
262
+ Authorization: `BEARER ${proof.jwt}`
263
+ });
264
+ } else {
265
+ const signedProof = await signOwnershipProof(proof);
266
+ response = await this.guard.authMethods({
267
+ proof: {
268
+ wallet: signedProof.walletAddress,
269
+ timestamp: signedProof.timestamp.getTime(),
270
+ signer: signedProof.signerAddress,
271
+ signature: signedProof.signature
272
+ }
273
+ });
274
+ }
275
+ return response.methods.map(parseAuthMethod);
276
+ }
277
+ async setPin(pin, proof) {
278
+ const signedProof = await signAuthUpdateProof(proof);
279
+ if (pin === undefined) {
280
+ await this.guard.resetPIN({
281
+ timestamp: signedProof.timestamp.getTime(),
282
+ signature: signedProof.signature
283
+ }, {
284
+ Authorization: `BEARER ${proof.jwt}`
285
+ });
286
+ } else {
287
+ await this.guard.setPIN({
288
+ pin,
289
+ timestamp: signedProof.timestamp.getTime(),
290
+ signature: signedProof.signature
291
+ }, {
292
+ Authorization: `BEARER ${proof.jwt}`
293
+ });
215
294
  }
216
295
  }
296
+ resetPin(proof) {
297
+ return this.setPin(undefined, proof);
298
+ }
299
+ async createTotp(proof) {
300
+ const signedProof = await signAuthUpdateProof(proof);
301
+ const {
302
+ uri
303
+ } = await this.guard.createTOTP({
304
+ timestamp: signedProof.timestamp.getTime(),
305
+ signature: signedProof.signature
306
+ }, {
307
+ Authorization: `BEARER ${proof.jwt}`
308
+ });
309
+ return new URL(uri);
310
+ }
311
+ async commitTotp(token, jwt) {
312
+ const {
313
+ codes
314
+ } = await this.guard.commitTOTP({
315
+ token
316
+ }, {
317
+ Authorization: `BEARER ${jwt}`
318
+ });
319
+ return codes;
320
+ }
321
+ async resetTotp(proof) {
322
+ const signedProof = await signAuthUpdateProof(proof);
323
+ await this.guard.resetTOTP({
324
+ timestamp: signedProof.timestamp.getTime(),
325
+ signature: signedProof.signature
326
+ }, {
327
+ Authorization: `BEARER ${proof.jwt}`
328
+ });
329
+ }
330
+ async reset2fa(recoveryCode, proof) {
331
+ if ('jwt' in proof) {
332
+ await this.guard.reset2FA({
333
+ code: recoveryCode
334
+ }, {
335
+ Authorization: `BEARER ${proof.jwt}`
336
+ });
337
+ } else {
338
+ const signedProof = await signOwnershipProof(proof);
339
+ await this.guard.reset2FA({
340
+ code: recoveryCode,
341
+ proof: {
342
+ wallet: signedProof.walletAddress,
343
+ timestamp: signedProof.timestamp.getTime(),
344
+ signer: signedProof.signerAddress,
345
+ signature: signedProof.signature
346
+ }
347
+ });
348
+ }
349
+ }
350
+ async getRecoveryCodes(proof) {
351
+ const signedProof = await signAuthUpdateProof(proof);
352
+ const {
353
+ codes
354
+ } = await this.guard.recoveryCodes({
355
+ timestamp: signedProof.timestamp.getTime(),
356
+ signature: signedProof.signature
357
+ }, {
358
+ Authorization: `BEARER ${proof.jwt}`
359
+ });
360
+ return codes;
361
+ }
362
+ async resetRecoveryCodes(proof) {
363
+ const signedProof = await signAuthUpdateProof(proof);
364
+ const {
365
+ codes
366
+ } = await this.guard.resetRecoveryCodes({
367
+ timestamp: signedProof.timestamp.getTime(),
368
+ signature: signedProof.signature
369
+ }, {
370
+ Authorization: `BEARER ${proof.jwt}`
371
+ });
372
+ return codes;
373
+ }
374
+ packMsgAndSig(address, msg, sig, chainId) {
375
+ return ethers.utils.defaultAbiCoder.encode(['address', 'uint256', 'bytes', 'bytes'], [address, chainId, msg, sig]);
376
+ }
217
377
  suffix() {
218
378
  return this.appendSuffix ? [3] : [];
219
379
  }
220
380
  }
381
+ let AuthMethod = /*#__PURE__*/function (AuthMethod) {
382
+ AuthMethod["PIN"] = "PIN";
383
+ AuthMethod["TOTP"] = "TOTP";
384
+ return AuthMethod;
385
+ }({});
386
+ function parseAuthMethod(method) {
387
+ switch (method) {
388
+ case AuthMethod.PIN:
389
+ case AuthMethod.TOTP:
390
+ return method;
391
+ default:
392
+ throw new Error(`unknown auth method '${method}'`);
393
+ }
394
+ }
395
+ function isSignedOwnershipProof(proof) {
396
+ return 'signerAddress' in proof && typeof proof.signerAddress === 'string';
397
+ }
398
+ async function signOwnershipProof(proof) {
399
+ if (isSignedOwnershipProof(proof)) {
400
+ return proof;
401
+ } else {
402
+ const signer = signers.isSapientSigner(proof.signer) ? proof.signer : new signers.SignerWrapper(proof.signer);
403
+ const signerAddress = await signer.getAddress();
404
+ const timestamp = new Date();
405
+ const typedData = getOwnershipProofTypedData(proof.walletAddress, timestamp);
406
+ const digest = encodeTypedDataDigest(typedData);
407
+ const randomId = ethers.utils.hexlify(ethers.utils.randomBytes(32));
408
+ return new Promise((resolve, reject) => signer.requestSignature(randomId, digest, {}, {
409
+ onSignature(signature) {
410
+ resolve({
411
+ walletAddress: proof.walletAddress,
412
+ timestamp,
413
+ signerAddress,
414
+ signature: ethers.utils.hexlify(signature)
415
+ });
416
+ },
417
+ onRejection: reject,
418
+ onStatus(_situation) {}
419
+ }));
420
+ }
421
+ }
422
+ async function signAuthUpdateProof(proof) {
423
+ if ('wallet' in proof) {
424
+ var _typedData$domain$cha;
425
+ const timestamp = new Date();
426
+ const typedData = getAuthUpdateProofTypedData(timestamp);
427
+ const signature = await proof.wallet.signTypedData(typedData.domain, typedData.types, typedData.message, (_typedData$domain$cha = typedData.domain.chainId) != null ? _typedData$domain$cha : 1, 'eip6492');
428
+ return {
429
+ jwt: proof.jwt,
430
+ timestamp,
431
+ signature
432
+ };
433
+ } else {
434
+ return proof;
435
+ }
436
+ }
437
+ function getOwnershipProofTypedData(wallet, timestamp) {
438
+ return {
439
+ domain,
440
+ types: {
441
+ AuthMethods: [{
442
+ name: 'wallet',
443
+ type: 'address'
444
+ }, {
445
+ name: 'timestamp',
446
+ type: 'string'
447
+ }]
448
+ },
449
+ message: {
450
+ wallet: ethers.utils.getAddress(wallet),
451
+ timestamp: toUTCString(timestamp)
452
+ }
453
+ };
454
+ }
455
+ function getAuthUpdateProofTypedData(timestamp) {
456
+ return {
457
+ domain,
458
+ types: {
459
+ AuthUpdate: [{
460
+ name: 'timestamp',
461
+ type: 'string'
462
+ }]
463
+ },
464
+ message: {
465
+ timestamp: toUTCString(timestamp)
466
+ }
467
+ };
468
+ }
469
+ const domain = {
470
+ name: 'Sequence Guard',
471
+ version: '1',
472
+ chainId: 1
473
+ };
474
+ function toUTCString(date) {
475
+ return date.toUTCString().replace('GMT', 'UTC');
476
+ }
221
477
 
222
- export { Guard, GuardSigner, WebRPCSchemaHash, WebRPCSchemaVersion, WebRPCVersion };
478
+ 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 = "b1cf87e4fb4cc6bef4c479bd613bfb462d1f788e";
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,69 @@ 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
+ }
104
+ export interface SetPINArgs {
105
+ pin: string;
106
+ timestamp: number;
107
+ signature: string;
108
+ }
109
+ export interface SetPINReturn {
110
+ }
111
+ export interface ResetPINArgs {
112
+ timestamp: number;
113
+ signature: string;
114
+ }
115
+ export interface ResetPINReturn {
116
+ }
117
+ export interface CreateTOTPArgs {
118
+ timestamp: number;
119
+ signature: string;
120
+ }
121
+ export interface CreateTOTPReturn {
122
+ uri: string;
123
+ }
124
+ export interface CommitTOTPArgs {
125
+ token: string;
126
+ }
127
+ export interface CommitTOTPReturn {
128
+ codes: Array<RecoveryCode>;
129
+ }
130
+ export interface ResetTOTPArgs {
131
+ timestamp: number;
132
+ signature: string;
133
+ }
134
+ export interface ResetTOTPReturn {
135
+ }
136
+ export interface Reset2FAArgs {
137
+ code: string;
138
+ proof?: OwnershipProof;
139
+ }
140
+ export interface Reset2FAReturn {
141
+ }
142
+ export interface RecoveryCodesArgs {
143
+ timestamp: number;
144
+ signature: string;
145
+ }
146
+ export interface RecoveryCodesReturn {
147
+ codes: Array<RecoveryCode>;
148
+ }
149
+ export interface ResetRecoveryCodesArgs {
150
+ timestamp: number;
151
+ signature: string;
152
+ }
153
+ export interface ResetRecoveryCodesReturn {
154
+ codes: Array<RecoveryCode>;
155
+ }
73
156
  export declare class Guard implements Guard {
74
157
  protected hostname: string;
75
158
  protected fetch: Fetch;
@@ -82,6 +165,15 @@ export declare class Guard implements Guard {
82
165
  getSignerConfig: (args: GetSignerConfigArgs, headers?: object | undefined) => Promise<GetSignerConfigReturn>;
83
166
  sign: (args: SignArgs, headers?: object | undefined) => Promise<SignReturn>;
84
167
  signWith: (args: SignWithArgs, headers?: object | undefined) => Promise<SignWithReturn>;
168
+ authMethods: (args: AuthMethodsArgs, headers?: object | undefined) => Promise<AuthMethodsReturn>;
169
+ setPIN: (args: SetPINArgs, headers?: object | undefined) => Promise<SetPINReturn>;
170
+ resetPIN: (args: ResetPINArgs, headers?: object | undefined) => Promise<ResetPINReturn>;
171
+ createTOTP: (args: CreateTOTPArgs, headers?: object | undefined) => Promise<CreateTOTPReturn>;
172
+ commitTOTP: (args: CommitTOTPArgs, headers?: object | undefined) => Promise<CommitTOTPReturn>;
173
+ resetTOTP: (args: ResetTOTPArgs, headers?: object | undefined) => Promise<ResetTOTPReturn>;
174
+ reset2FA: (args: Reset2FAArgs, headers?: object | undefined) => Promise<Reset2FAReturn>;
175
+ recoveryCodes: (args: RecoveryCodesArgs, headers?: object | undefined) => Promise<RecoveryCodesReturn>;
176
+ resetRecoveryCodes: (args: ResetRecoveryCodesArgs, headers?: object | undefined) => Promise<ResetRecoveryCodesReturn>;
85
177
  }
86
178
  export interface WebRPCError extends Error {
87
179
  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.1",
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.1",
14
+ "@0xsequence/core": "1.4.1",
15
+ "@0xsequence/signhub": "1.4.1",
16
+ "@0xsequence/utils": "1.4.1"
15
17
  },
16
18
  "files": [
17
19
  "src",