@0xsequence/guard 2.3.39 → 3.0.0-beta.10
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/.turbo/turbo-build.log +5 -0
- package/CHANGELOG.md +3002 -0
- package/LICENSE +0 -17
- package/README.md +1 -2
- package/dist/{declarations/src → client}/guard.gen.d.ts +1 -0
- package/dist/client/guard.gen.d.ts.map +1 -0
- package/dist/client/guard.gen.js +552 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/local.d.ts +14 -0
- package/dist/local.d.ts.map +1 -0
- package/dist/local.js +13 -0
- package/dist/sequence.d.ts +14 -0
- package/dist/sequence.d.ts.map +1 -0
- package/dist/sequence.js +44 -0
- package/dist/types.d.ts +11 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +9 -0
- package/package.json +23 -19
- package/src/{guard.gen.ts → client/guard.gen.ts} +124 -116
- package/src/index.ts +6 -2
- package/src/local.ts +23 -0
- package/src/sequence.ts +56 -0
- package/src/types.ts +27 -0
- package/test/sequence.test.ts +189 -0
- package/tsconfig.json +10 -0
- package/dist/0xsequence-guard.cjs.d.ts +0 -2
- package/dist/0xsequence-guard.cjs.dev.js +0 -785
- package/dist/0xsequence-guard.cjs.js +0 -7
- package/dist/0xsequence-guard.cjs.prod.js +0 -785
- package/dist/0xsequence-guard.esm.js +0 -775
- package/dist/declarations/src/index.d.ts +0 -2
- package/dist/declarations/src/signer.d.ts +0 -66
- package/src/signer.ts +0 -310
|
@@ -34,7 +34,7 @@ export function VersionFromHeader(headers: Headers): WebrpcGenVersions {
|
|
|
34
34
|
codeGenName: '',
|
|
35
35
|
codeGenVersion: '',
|
|
36
36
|
schemaName: '',
|
|
37
|
-
schemaVersion: ''
|
|
37
|
+
schemaVersion: '',
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
|
|
@@ -49,7 +49,7 @@ function parseWebrpcGenVersions(header: string): WebrpcGenVersions {
|
|
|
49
49
|
codeGenName: '',
|
|
50
50
|
codeGenVersion: '',
|
|
51
51
|
schemaName: '',
|
|
52
|
-
schemaVersion: ''
|
|
52
|
+
schemaVersion: '',
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
|
|
@@ -62,7 +62,7 @@ function parseWebrpcGenVersions(header: string): WebrpcGenVersions {
|
|
|
62
62
|
codeGenName: codeGenName ?? '',
|
|
63
63
|
codeGenVersion: codeGenVersion ?? '',
|
|
64
64
|
schemaName: schemaName ?? '',
|
|
65
|
-
schemaVersion: schemaVersion ?? ''
|
|
65
|
+
schemaVersion: schemaVersion ?? '',
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
|
|
@@ -74,14 +74,14 @@ export enum PayloadType {
|
|
|
74
74
|
Calls = 'Calls',
|
|
75
75
|
Message = 'Message',
|
|
76
76
|
ConfigUpdate = 'ConfigUpdate',
|
|
77
|
-
SessionImplicitAuthorize = 'SessionImplicitAuthorize'
|
|
77
|
+
SessionImplicitAuthorize = 'SessionImplicitAuthorize',
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
export enum SignatureType {
|
|
81
81
|
Hash = 'Hash',
|
|
82
82
|
Sapient = 'Sapient',
|
|
83
83
|
EthSign = 'EthSign',
|
|
84
|
-
Erc1271 = 'Erc1271'
|
|
84
|
+
Erc1271 = 'Erc1271',
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
export interface Version {
|
|
@@ -206,7 +206,11 @@ export interface Guard {
|
|
|
206
206
|
* Called by sequence.app when the user is viewing their recovery codes.
|
|
207
207
|
* Requires both a JWT and a wallet signature.
|
|
208
208
|
*/
|
|
209
|
-
resetRecoveryCodes(
|
|
209
|
+
resetRecoveryCodes(
|
|
210
|
+
args: ResetRecoveryCodesArgs,
|
|
211
|
+
headers?: object,
|
|
212
|
+
signal?: AbortSignal,
|
|
213
|
+
): Promise<ResetRecoveryCodesReturn>
|
|
210
214
|
}
|
|
211
215
|
|
|
212
216
|
export interface PingArgs {}
|
|
@@ -347,238 +351,242 @@ export class Guard implements Guard {
|
|
|
347
351
|
|
|
348
352
|
ping = (headers?: object, signal?: AbortSignal): Promise<PingReturn> => {
|
|
349
353
|
return this.fetch(this.url('Ping'), createHTTPRequest({}, headers, signal)).then(
|
|
350
|
-
res => {
|
|
351
|
-
return buildResponse(res).then(_data => {
|
|
354
|
+
(res) => {
|
|
355
|
+
return buildResponse(res).then((_data) => {
|
|
352
356
|
return {
|
|
353
|
-
status: <boolean>_data.status
|
|
357
|
+
status: <boolean>_data.status,
|
|
354
358
|
}
|
|
355
359
|
})
|
|
356
360
|
},
|
|
357
|
-
error => {
|
|
361
|
+
(error) => {
|
|
358
362
|
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
|
|
359
|
-
}
|
|
363
|
+
},
|
|
360
364
|
)
|
|
361
365
|
}
|
|
362
366
|
|
|
363
367
|
version = (headers?: object, signal?: AbortSignal): Promise<VersionReturn> => {
|
|
364
368
|
return this.fetch(this.url('Version'), createHTTPRequest({}, headers, signal)).then(
|
|
365
|
-
res => {
|
|
366
|
-
return buildResponse(res).then(_data => {
|
|
369
|
+
(res) => {
|
|
370
|
+
return buildResponse(res).then((_data) => {
|
|
367
371
|
return {
|
|
368
|
-
version: <Version>_data.version
|
|
372
|
+
version: <Version>_data.version,
|
|
369
373
|
}
|
|
370
374
|
})
|
|
371
375
|
},
|
|
372
|
-
error => {
|
|
376
|
+
(error) => {
|
|
373
377
|
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
|
|
374
|
-
}
|
|
378
|
+
},
|
|
375
379
|
)
|
|
376
380
|
}
|
|
377
381
|
|
|
378
382
|
runtimeStatus = (headers?: object, signal?: AbortSignal): Promise<RuntimeStatusReturn> => {
|
|
379
383
|
return this.fetch(this.url('RuntimeStatus'), createHTTPRequest({}, headers, signal)).then(
|
|
380
|
-
res => {
|
|
381
|
-
return buildResponse(res).then(_data => {
|
|
384
|
+
(res) => {
|
|
385
|
+
return buildResponse(res).then((_data) => {
|
|
382
386
|
return {
|
|
383
|
-
status: <RuntimeStatus>_data.status
|
|
387
|
+
status: <RuntimeStatus>_data.status,
|
|
384
388
|
}
|
|
385
389
|
})
|
|
386
390
|
},
|
|
387
|
-
error => {
|
|
391
|
+
(error) => {
|
|
388
392
|
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
|
|
389
|
-
}
|
|
393
|
+
},
|
|
390
394
|
)
|
|
391
395
|
}
|
|
392
396
|
|
|
393
|
-
getSignerConfig = (
|
|
397
|
+
getSignerConfig = (
|
|
398
|
+
args: GetSignerConfigArgs,
|
|
399
|
+
headers?: object,
|
|
400
|
+
signal?: AbortSignal,
|
|
401
|
+
): Promise<GetSignerConfigReturn> => {
|
|
394
402
|
return this.fetch(this.url('GetSignerConfig'), createHTTPRequest(args, headers, signal)).then(
|
|
395
|
-
res => {
|
|
396
|
-
return buildResponse(res).then(_data => {
|
|
403
|
+
(res) => {
|
|
404
|
+
return buildResponse(res).then((_data) => {
|
|
397
405
|
return {
|
|
398
|
-
signerConfig: <WalletConfig>_data.signerConfig
|
|
406
|
+
signerConfig: <WalletConfig>_data.signerConfig,
|
|
399
407
|
}
|
|
400
408
|
})
|
|
401
409
|
},
|
|
402
|
-
error => {
|
|
410
|
+
(error) => {
|
|
403
411
|
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
|
|
404
|
-
}
|
|
412
|
+
},
|
|
405
413
|
)
|
|
406
414
|
}
|
|
407
415
|
|
|
408
416
|
sign = (args: SignArgs, headers?: object, signal?: AbortSignal): Promise<SignReturn> => {
|
|
409
417
|
return this.fetch(this.url('Sign'), createHTTPRequest(args, headers, signal)).then(
|
|
410
|
-
res => {
|
|
411
|
-
return buildResponse(res).then(_data => {
|
|
418
|
+
(res) => {
|
|
419
|
+
return buildResponse(res).then((_data) => {
|
|
412
420
|
return {
|
|
413
|
-
sig: <string>_data.sig
|
|
421
|
+
sig: <string>_data.sig,
|
|
414
422
|
}
|
|
415
423
|
})
|
|
416
424
|
},
|
|
417
|
-
error => {
|
|
425
|
+
(error) => {
|
|
418
426
|
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
|
|
419
|
-
}
|
|
427
|
+
},
|
|
420
428
|
)
|
|
421
429
|
}
|
|
422
430
|
|
|
423
431
|
signWith = (args: SignWithArgs, headers?: object, signal?: AbortSignal): Promise<SignWithReturn> => {
|
|
424
432
|
return this.fetch(this.url('SignWith'), createHTTPRequest(args, headers, signal)).then(
|
|
425
|
-
res => {
|
|
426
|
-
return buildResponse(res).then(_data => {
|
|
433
|
+
(res) => {
|
|
434
|
+
return buildResponse(res).then((_data) => {
|
|
427
435
|
return {
|
|
428
|
-
sig: <string>_data.sig
|
|
436
|
+
sig: <string>_data.sig,
|
|
429
437
|
}
|
|
430
438
|
})
|
|
431
439
|
},
|
|
432
|
-
error => {
|
|
440
|
+
(error) => {
|
|
433
441
|
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
|
|
434
|
-
}
|
|
442
|
+
},
|
|
435
443
|
)
|
|
436
444
|
}
|
|
437
445
|
|
|
438
446
|
patch = (args: PatchArgs, headers?: object, signal?: AbortSignal): Promise<PatchReturn> => {
|
|
439
447
|
return this.fetch(this.url('Patch'), createHTTPRequest(args, headers, signal)).then(
|
|
440
|
-
res => {
|
|
441
|
-
return buildResponse(res).then(_data => {
|
|
448
|
+
(res) => {
|
|
449
|
+
return buildResponse(res).then((_data) => {
|
|
442
450
|
return {
|
|
443
|
-
txs: <any>_data.txs
|
|
451
|
+
txs: <any>_data.txs,
|
|
444
452
|
}
|
|
445
453
|
})
|
|
446
454
|
},
|
|
447
|
-
error => {
|
|
455
|
+
(error) => {
|
|
448
456
|
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
|
|
449
|
-
}
|
|
457
|
+
},
|
|
450
458
|
)
|
|
451
459
|
}
|
|
452
460
|
|
|
453
461
|
authMethods = (args: AuthMethodsArgs, headers?: object, signal?: AbortSignal): Promise<AuthMethodsReturn> => {
|
|
454
462
|
return this.fetch(this.url('AuthMethods'), createHTTPRequest(args, headers, signal)).then(
|
|
455
|
-
res => {
|
|
456
|
-
return buildResponse(res).then(_data => {
|
|
463
|
+
(res) => {
|
|
464
|
+
return buildResponse(res).then((_data) => {
|
|
457
465
|
return {
|
|
458
466
|
methods: <Array<string>>_data.methods,
|
|
459
|
-
active: <boolean>_data.active
|
|
467
|
+
active: <boolean>_data.active,
|
|
460
468
|
}
|
|
461
469
|
})
|
|
462
470
|
},
|
|
463
|
-
error => {
|
|
471
|
+
(error) => {
|
|
464
472
|
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
|
|
465
|
-
}
|
|
473
|
+
},
|
|
466
474
|
)
|
|
467
475
|
}
|
|
468
476
|
|
|
469
477
|
setPIN = (args: SetPINArgs, headers?: object, signal?: AbortSignal): Promise<SetPINReturn> => {
|
|
470
478
|
return this.fetch(this.url('SetPIN'), createHTTPRequest(args, headers, signal)).then(
|
|
471
|
-
res => {
|
|
472
|
-
return buildResponse(res).then(_data => {
|
|
479
|
+
(res) => {
|
|
480
|
+
return buildResponse(res).then((_data) => {
|
|
473
481
|
return {}
|
|
474
482
|
})
|
|
475
483
|
},
|
|
476
|
-
error => {
|
|
484
|
+
(error) => {
|
|
477
485
|
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
|
|
478
|
-
}
|
|
486
|
+
},
|
|
479
487
|
)
|
|
480
488
|
}
|
|
481
489
|
|
|
482
490
|
resetPIN = (args: ResetPINArgs, headers?: object, signal?: AbortSignal): Promise<ResetPINReturn> => {
|
|
483
491
|
return this.fetch(this.url('ResetPIN'), createHTTPRequest(args, headers, signal)).then(
|
|
484
|
-
res => {
|
|
485
|
-
return buildResponse(res).then(_data => {
|
|
492
|
+
(res) => {
|
|
493
|
+
return buildResponse(res).then((_data) => {
|
|
486
494
|
return {}
|
|
487
495
|
})
|
|
488
496
|
},
|
|
489
|
-
error => {
|
|
497
|
+
(error) => {
|
|
490
498
|
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
|
|
491
|
-
}
|
|
499
|
+
},
|
|
492
500
|
)
|
|
493
501
|
}
|
|
494
502
|
|
|
495
503
|
createTOTP = (args: CreateTOTPArgs, headers?: object, signal?: AbortSignal): Promise<CreateTOTPReturn> => {
|
|
496
504
|
return this.fetch(this.url('CreateTOTP'), createHTTPRequest(args, headers, signal)).then(
|
|
497
|
-
res => {
|
|
498
|
-
return buildResponse(res).then(_data => {
|
|
505
|
+
(res) => {
|
|
506
|
+
return buildResponse(res).then((_data) => {
|
|
499
507
|
return {
|
|
500
|
-
uri: <string>_data.uri
|
|
508
|
+
uri: <string>_data.uri,
|
|
501
509
|
}
|
|
502
510
|
})
|
|
503
511
|
},
|
|
504
|
-
error => {
|
|
512
|
+
(error) => {
|
|
505
513
|
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
|
|
506
|
-
}
|
|
514
|
+
},
|
|
507
515
|
)
|
|
508
516
|
}
|
|
509
517
|
|
|
510
518
|
commitTOTP = (args: CommitTOTPArgs, headers?: object, signal?: AbortSignal): Promise<CommitTOTPReturn> => {
|
|
511
519
|
return this.fetch(this.url('CommitTOTP'), createHTTPRequest(args, headers, signal)).then(
|
|
512
|
-
res => {
|
|
513
|
-
return buildResponse(res).then(_data => {
|
|
520
|
+
(res) => {
|
|
521
|
+
return buildResponse(res).then((_data) => {
|
|
514
522
|
return {
|
|
515
|
-
codes: <Array<RecoveryCode>>_data.codes
|
|
523
|
+
codes: <Array<RecoveryCode>>_data.codes,
|
|
516
524
|
}
|
|
517
525
|
})
|
|
518
526
|
},
|
|
519
|
-
error => {
|
|
527
|
+
(error) => {
|
|
520
528
|
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
|
|
521
|
-
}
|
|
529
|
+
},
|
|
522
530
|
)
|
|
523
531
|
}
|
|
524
532
|
|
|
525
533
|
resetTOTP = (args: ResetTOTPArgs, headers?: object, signal?: AbortSignal): Promise<ResetTOTPReturn> => {
|
|
526
534
|
return this.fetch(this.url('ResetTOTP'), createHTTPRequest(args, headers, signal)).then(
|
|
527
|
-
res => {
|
|
528
|
-
return buildResponse(res).then(_data => {
|
|
535
|
+
(res) => {
|
|
536
|
+
return buildResponse(res).then((_data) => {
|
|
529
537
|
return {}
|
|
530
538
|
})
|
|
531
539
|
},
|
|
532
|
-
error => {
|
|
540
|
+
(error) => {
|
|
533
541
|
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
|
|
534
|
-
}
|
|
542
|
+
},
|
|
535
543
|
)
|
|
536
544
|
}
|
|
537
545
|
|
|
538
546
|
reset2FA = (args: Reset2FAArgs, headers?: object, signal?: AbortSignal): Promise<Reset2FAReturn> => {
|
|
539
547
|
return this.fetch(this.url('Reset2FA'), createHTTPRequest(args, headers, signal)).then(
|
|
540
|
-
res => {
|
|
541
|
-
return buildResponse(res).then(_data => {
|
|
548
|
+
(res) => {
|
|
549
|
+
return buildResponse(res).then((_data) => {
|
|
542
550
|
return {}
|
|
543
551
|
})
|
|
544
552
|
},
|
|
545
|
-
error => {
|
|
553
|
+
(error) => {
|
|
546
554
|
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
|
|
547
|
-
}
|
|
555
|
+
},
|
|
548
556
|
)
|
|
549
557
|
}
|
|
550
558
|
|
|
551
559
|
recoveryCodes = (args: RecoveryCodesArgs, headers?: object, signal?: AbortSignal): Promise<RecoveryCodesReturn> => {
|
|
552
560
|
return this.fetch(this.url('RecoveryCodes'), createHTTPRequest(args, headers, signal)).then(
|
|
553
|
-
res => {
|
|
554
|
-
return buildResponse(res).then(_data => {
|
|
561
|
+
(res) => {
|
|
562
|
+
return buildResponse(res).then((_data) => {
|
|
555
563
|
return {
|
|
556
|
-
codes: <Array<RecoveryCode>>_data.codes
|
|
564
|
+
codes: <Array<RecoveryCode>>_data.codes,
|
|
557
565
|
}
|
|
558
566
|
})
|
|
559
567
|
},
|
|
560
|
-
error => {
|
|
568
|
+
(error) => {
|
|
561
569
|
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
|
|
562
|
-
}
|
|
570
|
+
},
|
|
563
571
|
)
|
|
564
572
|
}
|
|
565
573
|
|
|
566
574
|
resetRecoveryCodes = (
|
|
567
575
|
args: ResetRecoveryCodesArgs,
|
|
568
576
|
headers?: object,
|
|
569
|
-
signal?: AbortSignal
|
|
577
|
+
signal?: AbortSignal,
|
|
570
578
|
): Promise<ResetRecoveryCodesReturn> => {
|
|
571
579
|
return this.fetch(this.url('ResetRecoveryCodes'), createHTTPRequest(args, headers, signal)).then(
|
|
572
|
-
res => {
|
|
573
|
-
return buildResponse(res).then(_data => {
|
|
580
|
+
(res) => {
|
|
581
|
+
return buildResponse(res).then((_data) => {
|
|
574
582
|
return {
|
|
575
|
-
codes: <Array<RecoveryCode>>_data.codes
|
|
583
|
+
codes: <Array<RecoveryCode>>_data.codes,
|
|
576
584
|
}
|
|
577
585
|
})
|
|
578
586
|
},
|
|
579
|
-
error => {
|
|
587
|
+
(error) => {
|
|
580
588
|
throw WebrpcRequestFailedError.new({ cause: `fetch(): ${error.message || ''}` })
|
|
581
|
-
}
|
|
589
|
+
},
|
|
582
590
|
)
|
|
583
591
|
}
|
|
584
592
|
}
|
|
@@ -591,12 +599,12 @@ const createHTTPRequest = (body: object = {}, headers: object = {}, signal: Abor
|
|
|
591
599
|
method: 'POST',
|
|
592
600
|
headers: reqHeaders,
|
|
593
601
|
body: JSON.stringify(body || {}),
|
|
594
|
-
signal
|
|
602
|
+
signal,
|
|
595
603
|
}
|
|
596
604
|
}
|
|
597
605
|
|
|
598
606
|
const buildResponse = (res: Response): Promise<any> => {
|
|
599
|
-
return res.text().then(text => {
|
|
607
|
+
return res.text().then((text) => {
|
|
600
608
|
let data
|
|
601
609
|
try {
|
|
602
610
|
data = JSON.parse(text)
|
|
@@ -607,7 +615,7 @@ const buildResponse = (res: Response): Promise<any> => {
|
|
|
607
615
|
}
|
|
608
616
|
throw WebrpcBadResponseError.new({
|
|
609
617
|
status: res.status,
|
|
610
|
-
cause: `JSON.parse(): ${message}: response text: ${text}
|
|
618
|
+
cause: `JSON.parse(): ${message}: response text: ${text}`,
|
|
611
619
|
})
|
|
612
620
|
}
|
|
613
621
|
if (!res.ok) {
|
|
@@ -656,7 +664,7 @@ export class WebrpcEndpointError extends WebrpcError {
|
|
|
656
664
|
code: number = 0,
|
|
657
665
|
message: string = `endpoint error`,
|
|
658
666
|
status: number = 0,
|
|
659
|
-
cause?: string
|
|
667
|
+
cause?: string,
|
|
660
668
|
) {
|
|
661
669
|
super(name, code, message, status, cause)
|
|
662
670
|
Object.setPrototypeOf(this, WebrpcEndpointError.prototype)
|
|
@@ -669,7 +677,7 @@ export class WebrpcRequestFailedError extends WebrpcError {
|
|
|
669
677
|
code: number = -1,
|
|
670
678
|
message: string = `request failed`,
|
|
671
679
|
status: number = 0,
|
|
672
|
-
cause?: string
|
|
680
|
+
cause?: string,
|
|
673
681
|
) {
|
|
674
682
|
super(name, code, message, status, cause)
|
|
675
683
|
Object.setPrototypeOf(this, WebrpcRequestFailedError.prototype)
|
|
@@ -682,7 +690,7 @@ export class WebrpcBadRouteError extends WebrpcError {
|
|
|
682
690
|
code: number = -2,
|
|
683
691
|
message: string = `bad route`,
|
|
684
692
|
status: number = 0,
|
|
685
|
-
cause?: string
|
|
693
|
+
cause?: string,
|
|
686
694
|
) {
|
|
687
695
|
super(name, code, message, status, cause)
|
|
688
696
|
Object.setPrototypeOf(this, WebrpcBadRouteError.prototype)
|
|
@@ -695,7 +703,7 @@ export class WebrpcBadMethodError extends WebrpcError {
|
|
|
695
703
|
code: number = -3,
|
|
696
704
|
message: string = `bad method`,
|
|
697
705
|
status: number = 0,
|
|
698
|
-
cause?: string
|
|
706
|
+
cause?: string,
|
|
699
707
|
) {
|
|
700
708
|
super(name, code, message, status, cause)
|
|
701
709
|
Object.setPrototypeOf(this, WebrpcBadMethodError.prototype)
|
|
@@ -708,7 +716,7 @@ export class WebrpcBadRequestError extends WebrpcError {
|
|
|
708
716
|
code: number = -4,
|
|
709
717
|
message: string = `bad request`,
|
|
710
718
|
status: number = 0,
|
|
711
|
-
cause?: string
|
|
719
|
+
cause?: string,
|
|
712
720
|
) {
|
|
713
721
|
super(name, code, message, status, cause)
|
|
714
722
|
Object.setPrototypeOf(this, WebrpcBadRequestError.prototype)
|
|
@@ -721,7 +729,7 @@ export class WebrpcBadResponseError extends WebrpcError {
|
|
|
721
729
|
code: number = -5,
|
|
722
730
|
message: string = `bad response`,
|
|
723
731
|
status: number = 0,
|
|
724
|
-
cause?: string
|
|
732
|
+
cause?: string,
|
|
725
733
|
) {
|
|
726
734
|
super(name, code, message, status, cause)
|
|
727
735
|
Object.setPrototypeOf(this, WebrpcBadResponseError.prototype)
|
|
@@ -734,7 +742,7 @@ export class WebrpcServerPanicError extends WebrpcError {
|
|
|
734
742
|
code: number = -6,
|
|
735
743
|
message: string = `server panic`,
|
|
736
744
|
status: number = 0,
|
|
737
|
-
cause?: string
|
|
745
|
+
cause?: string,
|
|
738
746
|
) {
|
|
739
747
|
super(name, code, message, status, cause)
|
|
740
748
|
Object.setPrototypeOf(this, WebrpcServerPanicError.prototype)
|
|
@@ -747,7 +755,7 @@ export class WebrpcInternalErrorError extends WebrpcError {
|
|
|
747
755
|
code: number = -7,
|
|
748
756
|
message: string = `internal error`,
|
|
749
757
|
status: number = 0,
|
|
750
|
-
cause?: string
|
|
758
|
+
cause?: string,
|
|
751
759
|
) {
|
|
752
760
|
super(name, code, message, status, cause)
|
|
753
761
|
Object.setPrototypeOf(this, WebrpcInternalErrorError.prototype)
|
|
@@ -760,7 +768,7 @@ export class WebrpcClientDisconnectedError extends WebrpcError {
|
|
|
760
768
|
code: number = -8,
|
|
761
769
|
message: string = `client disconnected`,
|
|
762
770
|
status: number = 0,
|
|
763
|
-
cause?: string
|
|
771
|
+
cause?: string,
|
|
764
772
|
) {
|
|
765
773
|
super(name, code, message, status, cause)
|
|
766
774
|
Object.setPrototypeOf(this, WebrpcClientDisconnectedError.prototype)
|
|
@@ -773,7 +781,7 @@ export class WebrpcStreamLostError extends WebrpcError {
|
|
|
773
781
|
code: number = -9,
|
|
774
782
|
message: string = `stream lost`,
|
|
775
783
|
status: number = 0,
|
|
776
|
-
cause?: string
|
|
784
|
+
cause?: string,
|
|
777
785
|
) {
|
|
778
786
|
super(name, code, message, status, cause)
|
|
779
787
|
Object.setPrototypeOf(this, WebrpcStreamLostError.prototype)
|
|
@@ -786,7 +794,7 @@ export class WebrpcStreamFinishedError extends WebrpcError {
|
|
|
786
794
|
code: number = -10,
|
|
787
795
|
message: string = `stream finished`,
|
|
788
796
|
status: number = 0,
|
|
789
|
-
cause?: string
|
|
797
|
+
cause?: string,
|
|
790
798
|
) {
|
|
791
799
|
super(name, code, message, status, cause)
|
|
792
800
|
Object.setPrototypeOf(this, WebrpcStreamFinishedError.prototype)
|
|
@@ -801,7 +809,7 @@ export class UnauthorizedError extends WebrpcError {
|
|
|
801
809
|
code: number = 1000,
|
|
802
810
|
message: string = `Unauthorized access`,
|
|
803
811
|
status: number = 0,
|
|
804
|
-
cause?: string
|
|
812
|
+
cause?: string,
|
|
805
813
|
) {
|
|
806
814
|
super(name, code, message, status, cause)
|
|
807
815
|
Object.setPrototypeOf(this, UnauthorizedError.prototype)
|
|
@@ -814,7 +822,7 @@ export class PermissionDeniedError extends WebrpcError {
|
|
|
814
822
|
code: number = 1001,
|
|
815
823
|
message: string = `Permission denied`,
|
|
816
824
|
status: number = 0,
|
|
817
|
-
cause?: string
|
|
825
|
+
cause?: string,
|
|
818
826
|
) {
|
|
819
827
|
super(name, code, message, status, cause)
|
|
820
828
|
Object.setPrototypeOf(this, PermissionDeniedError.prototype)
|
|
@@ -827,7 +835,7 @@ export class SessionExpiredError extends WebrpcError {
|
|
|
827
835
|
code: number = 1002,
|
|
828
836
|
message: string = `Session expired`,
|
|
829
837
|
status: number = 0,
|
|
830
|
-
cause?: string
|
|
838
|
+
cause?: string,
|
|
831
839
|
) {
|
|
832
840
|
super(name, code, message, status, cause)
|
|
833
841
|
Object.setPrototypeOf(this, SessionExpiredError.prototype)
|
|
@@ -840,7 +848,7 @@ export class MethodNotFoundError extends WebrpcError {
|
|
|
840
848
|
code: number = 1003,
|
|
841
849
|
message: string = `Method not found`,
|
|
842
850
|
status: number = 0,
|
|
843
|
-
cause?: string
|
|
851
|
+
cause?: string,
|
|
844
852
|
) {
|
|
845
853
|
super(name, code, message, status, cause)
|
|
846
854
|
Object.setPrototypeOf(this, MethodNotFoundError.prototype)
|
|
@@ -853,7 +861,7 @@ export class RequestConflictError extends WebrpcError {
|
|
|
853
861
|
code: number = 1004,
|
|
854
862
|
message: string = `Conflict with target resource`,
|
|
855
863
|
status: number = 0,
|
|
856
|
-
cause?: string
|
|
864
|
+
cause?: string,
|
|
857
865
|
) {
|
|
858
866
|
super(name, code, message, status, cause)
|
|
859
867
|
Object.setPrototypeOf(this, RequestConflictError.prototype)
|
|
@@ -866,7 +874,7 @@ export class AbortedError extends WebrpcError {
|
|
|
866
874
|
code: number = 1005,
|
|
867
875
|
message: string = `Request aborted`,
|
|
868
876
|
status: number = 0,
|
|
869
|
-
cause?: string
|
|
877
|
+
cause?: string,
|
|
870
878
|
) {
|
|
871
879
|
super(name, code, message, status, cause)
|
|
872
880
|
Object.setPrototypeOf(this, AbortedError.prototype)
|
|
@@ -879,7 +887,7 @@ export class GeoblockedError extends WebrpcError {
|
|
|
879
887
|
code: number = 1006,
|
|
880
888
|
message: string = `Geoblocked region`,
|
|
881
889
|
status: number = 0,
|
|
882
|
-
cause?: string
|
|
890
|
+
cause?: string,
|
|
883
891
|
) {
|
|
884
892
|
super(name, code, message, status, cause)
|
|
885
893
|
Object.setPrototypeOf(this, GeoblockedError.prototype)
|
|
@@ -892,7 +900,7 @@ export class RateLimitedError extends WebrpcError {
|
|
|
892
900
|
code: number = 1007,
|
|
893
901
|
message: string = `Rate-limited. Please slow down.`,
|
|
894
902
|
status: number = 0,
|
|
895
|
-
cause?: string
|
|
903
|
+
cause?: string,
|
|
896
904
|
) {
|
|
897
905
|
super(name, code, message, status, cause)
|
|
898
906
|
Object.setPrototypeOf(this, RateLimitedError.prototype)
|
|
@@ -905,7 +913,7 @@ export class InvalidArgumentError extends WebrpcError {
|
|
|
905
913
|
code: number = 2001,
|
|
906
914
|
message: string = `Invalid argument`,
|
|
907
915
|
status: number = 0,
|
|
908
|
-
cause?: string
|
|
916
|
+
cause?: string,
|
|
909
917
|
) {
|
|
910
918
|
super(name, code, message, status, cause)
|
|
911
919
|
Object.setPrototypeOf(this, InvalidArgumentError.prototype)
|
|
@@ -918,7 +926,7 @@ export class UnavailableError extends WebrpcError {
|
|
|
918
926
|
code: number = 2002,
|
|
919
927
|
message: string = `Unavailable resource`,
|
|
920
928
|
status: number = 0,
|
|
921
|
-
cause?: string
|
|
929
|
+
cause?: string,
|
|
922
930
|
) {
|
|
923
931
|
super(name, code, message, status, cause)
|
|
924
932
|
Object.setPrototypeOf(this, UnavailableError.prototype)
|
|
@@ -931,7 +939,7 @@ export class QueryFailedError extends WebrpcError {
|
|
|
931
939
|
code: number = 2003,
|
|
932
940
|
message: string = `Query failed`,
|
|
933
941
|
status: number = 0,
|
|
934
|
-
cause?: string
|
|
942
|
+
cause?: string,
|
|
935
943
|
) {
|
|
936
944
|
super(name, code, message, status, cause)
|
|
937
945
|
Object.setPrototypeOf(this, QueryFailedError.prototype)
|
|
@@ -944,7 +952,7 @@ export class ValidationFailedError extends WebrpcError {
|
|
|
944
952
|
code: number = 2004,
|
|
945
953
|
message: string = `Validation Failed`,
|
|
946
954
|
status: number = 0,
|
|
947
|
-
cause?: string
|
|
955
|
+
cause?: string,
|
|
948
956
|
) {
|
|
949
957
|
super(name, code, message, status, cause)
|
|
950
958
|
Object.setPrototypeOf(this, ValidationFailedError.prototype)
|
|
@@ -957,7 +965,7 @@ export class NotFoundError extends WebrpcError {
|
|
|
957
965
|
code: number = 3000,
|
|
958
966
|
message: string = `Resource not found`,
|
|
959
967
|
status: number = 0,
|
|
960
|
-
cause?: string
|
|
968
|
+
cause?: string,
|
|
961
969
|
) {
|
|
962
970
|
super(name, code, message, status, cause)
|
|
963
971
|
Object.setPrototypeOf(this, NotFoundError.prototype)
|
|
@@ -970,7 +978,7 @@ export class RequiresTOTPError extends WebrpcError {
|
|
|
970
978
|
code: number = 6600,
|
|
971
979
|
message: string = `TOTP is required`,
|
|
972
980
|
status: number = 0,
|
|
973
|
-
cause?: string
|
|
981
|
+
cause?: string,
|
|
974
982
|
) {
|
|
975
983
|
super(name, code, message, status, cause)
|
|
976
984
|
Object.setPrototypeOf(this, RequiresTOTPError.prototype)
|
|
@@ -983,7 +991,7 @@ export class RequiresPINError extends WebrpcError {
|
|
|
983
991
|
code: number = 6601,
|
|
984
992
|
message: string = `PIN is required`,
|
|
985
993
|
status: number = 0,
|
|
986
|
-
cause?: string
|
|
994
|
+
cause?: string,
|
|
987
995
|
) {
|
|
988
996
|
super(name, code, message, status, cause)
|
|
989
997
|
Object.setPrototypeOf(this, RequiresPINError.prototype)
|
|
@@ -1016,7 +1024,7 @@ export enum errors {
|
|
|
1016
1024
|
ValidationFailed = 'ValidationFailed',
|
|
1017
1025
|
NotFound = 'NotFound',
|
|
1018
1026
|
RequiresTOTP = 'RequiresTOTP',
|
|
1019
|
-
RequiresPIN = 'RequiresPIN'
|
|
1027
|
+
RequiresPIN = 'RequiresPIN',
|
|
1020
1028
|
}
|
|
1021
1029
|
|
|
1022
1030
|
export enum WebrpcErrorCodes {
|
|
@@ -1045,7 +1053,7 @@ export enum WebrpcErrorCodes {
|
|
|
1045
1053
|
ValidationFailed = 2004,
|
|
1046
1054
|
NotFound = 3000,
|
|
1047
1055
|
RequiresTOTP = 6600,
|
|
1048
|
-
RequiresPIN = 6601
|
|
1056
|
+
RequiresPIN = 6601,
|
|
1049
1057
|
}
|
|
1050
1058
|
|
|
1051
1059
|
export const webrpcErrorByCode: { [code: number]: any } = {
|
|
@@ -1074,7 +1082,7 @@ export const webrpcErrorByCode: { [code: number]: any } = {
|
|
|
1074
1082
|
[2004]: ValidationFailedError,
|
|
1075
1083
|
[3000]: NotFoundError,
|
|
1076
1084
|
[6600]: RequiresTOTPError,
|
|
1077
|
-
[6601]: RequiresPINError
|
|
1085
|
+
[6601]: RequiresPINError,
|
|
1078
1086
|
}
|
|
1079
1087
|
|
|
1080
1088
|
export type Fetch = (input: RequestInfo, init?: RequestInit) => Promise<Response>
|
package/src/index.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export * from './types.js'
|
|
2
|
+
export { PayloadType, SignatureType, type Signature } from './client/guard.gen.js'
|
|
3
|
+
|
|
4
|
+
export * as Client from './client/guard.gen.js'
|
|
5
|
+
export * as Sequence from './sequence.js'
|
|
6
|
+
export * as Local from './local.js'
|
package/src/local.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Address, Hex, Bytes, Secp256k1, Hash } from 'ox'
|
|
2
|
+
import * as Client from './client/guard.gen.js'
|
|
3
|
+
import * as Types from './types.js'
|
|
4
|
+
|
|
5
|
+
export class Guard implements Types.Guard {
|
|
6
|
+
public readonly address: Address.Address
|
|
7
|
+
|
|
8
|
+
constructor(private readonly privateKey: Hex.Hex) {
|
|
9
|
+
const publicKey = Secp256k1.getPublicKey({ privateKey: this.privateKey })
|
|
10
|
+
this.address = Address.fromPublicKey(publicKey)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async signPayload(
|
|
14
|
+
wallet: Address.Address,
|
|
15
|
+
chainId: number,
|
|
16
|
+
type: Client.PayloadType,
|
|
17
|
+
digest: Bytes.Bytes,
|
|
18
|
+
message: Bytes.Bytes,
|
|
19
|
+
signatures?: Client.Signature[],
|
|
20
|
+
) {
|
|
21
|
+
return Secp256k1.sign({ privateKey: this.privateKey, payload: digest })
|
|
22
|
+
}
|
|
23
|
+
}
|