@onekeyfe/hd-core 1.1.32-alpha.4 → 1.1.34-alpha.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.
@@ -454,6 +454,66 @@ describe('KaspaSignTransaction protocol negotiation', () => {
454
454
  // Back to the current transaction after the previous one is streamed.
455
455
  expect(mockTypedCall.mock.calls[4][0]).toBe('KaspaTxAckInput');
456
456
  });
457
+
458
+ describe('previous-transaction id mismatch', () => {
459
+ const PREV_ID = 'aa'.repeat(32);
460
+ const withRefTxs = {
461
+ outputs: [{ satoshis: 100000, script: SCRIPT, address: ADDRESS }],
462
+ refTxs: [
463
+ {
464
+ txId: PREV_ID,
465
+ version: 0,
466
+ inputs: [],
467
+ outputs: [{ satoshis: '200000', script: SCRIPT }],
468
+ },
469
+ ],
470
+ };
471
+
472
+ const streamThenReject = (error: unknown) =>
473
+ mockTypedCall
474
+ .mockResolvedValueOnce(
475
+ txRequest({ request_type: 'KASPA_TX_PREV_META', prev_tx_id: PREV_ID })
476
+ )
477
+ .mockRejectedValueOnce(error);
478
+
479
+ it('surfaces the device rejection under its own error code', async () => {
480
+ streamThenReject(
481
+ ERRORS.TypedError(
482
+ HardwareErrorCode.RuntimeError,
483
+ 'Failure_ProcessError,Kaspa previous transaction id mismatch'
484
+ )
485
+ );
486
+
487
+ await expect(runMethod(withRefTxs)).rejects.toMatchObject({
488
+ errorCode: HardwareErrorCode.KaspaPrevTxIdMismatch,
489
+ });
490
+ // Never silently re-signs without refTxs.
491
+ expect(mockTypedCall).toHaveBeenCalledTimes(2);
492
+ });
493
+
494
+ it('leaves an unrelated device error untouched', async () => {
495
+ streamThenReject(
496
+ ERRORS.TypedError(
497
+ HardwareErrorCode.RuntimeError,
498
+ 'Failure_ProcessError,some other device error'
499
+ )
500
+ );
501
+
502
+ await expect(runMethod(withRefTxs)).rejects.toMatchObject({
503
+ errorCode: HardwareErrorCode.RuntimeError,
504
+ });
505
+ expect(mockTypedCall).toHaveBeenCalledTimes(2);
506
+ });
507
+
508
+ it('leaves user cancellation untouched', async () => {
509
+ streamThenReject(ERRORS.TypedError(HardwareErrorCode.ActionCancelled));
510
+
511
+ await expect(runMethod(withRefTxs)).rejects.toMatchObject({
512
+ errorCode: HardwareErrorCode.ActionCancelled,
513
+ });
514
+ expect(mockTypedCall).toHaveBeenCalledTimes(2);
515
+ });
516
+ });
457
517
  });
458
518
 
459
519
  describe('KaspaSignTransaction wire encoding', () => {
@@ -1 +1 @@
1
- {"version":3,"file":"KaspaSignTransaction.d.ts","sourceRoot":"","sources":["../../../src/api/kaspa/KaspaSignTransaction.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAK3C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,KAAK,EAGV,0BAA0B,EAC1B,cAAc,EACf,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAEV,cAAc,EAEd,SAAS,EACV,MAAM,wBAAwB,CAAC;AAQhC,MAAM,CAAC,OAAO,OAAO,oBAAqB,SAAQ,UAAU,CAAC,0BAA0B,CAAC;IACtF,SAAS,UAAS;IAGlB,cAAc,UAAS;IAEvB,iBAAiB,UAAS;IAE1B,IAAI;IA4GJ,eAAe;;;;;;;;IAWf,uBAAuB;;;;;;;;IAejB,gBAAgB,CACpB,SAAS,EAAE,SAAS,EACpB,GAAG,EAAE,oBAAoB,CAAC,qBAAqB,CAAC,GAAG,oBAAoB,CAAC,eAAe,CAAC,EACxF,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,cAAc,EAAE,GAC1B,OAAO,CAAC,cAAc,EAAE,CAAC;IA0CtB,cAAc,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM;IA8ElF,YAAY,CAChB,SAAS,EAAE,SAAS,EACpB,aAAa,EAAE,oBAAoB,CAAC,gBAAgB,CAAC,GACpD,OAAO,CAAC,cAAc,EAAE,CAAC;IAmGtB,GAAG;CA4FV"}
1
+ {"version":3,"file":"KaspaSignTransaction.d.ts","sourceRoot":"","sources":["../../../src/api/kaspa/KaspaSignTransaction.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAK3C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,KAAK,EAGV,0BAA0B,EAC1B,cAAc,EACf,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAEV,cAAc,EAEd,SAAS,EACV,MAAM,wBAAwB,CAAC;AAQhC,MAAM,CAAC,OAAO,OAAO,oBAAqB,SAAQ,UAAU,CAAC,0BAA0B,CAAC;IACtF,SAAS,UAAS;IAGlB,cAAc,UAAS;IAEvB,iBAAiB,UAAS;IAE1B,IAAI;IA4GJ,eAAe;;;;;;;;IAWf,uBAAuB;;;;;;;;IAejB,gBAAgB,CACpB,SAAS,EAAE,SAAS,EACpB,GAAG,EAAE,oBAAoB,CAAC,qBAAqB,CAAC,GAAG,oBAAoB,CAAC,eAAe,CAAC,EACxF,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,cAAc,EAAE,GAC1B,OAAO,CAAC,cAAc,EAAE,CAAC;IA0CtB,cAAc,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM;IA8ElF,YAAY,CAChB,SAAS,EAAE,SAAS,EACpB,aAAa,EAAE,oBAAoB,CAAC,gBAAgB,CAAC,GACpD,OAAO,CAAC,cAAc,EAAE,CAAC;IAmGtB,GAAG;CAuGV"}
@@ -1 +1 @@
1
- {"version":3,"file":"TransferSerialize.d.ts","sourceRoot":"","sources":["../../../../src/api/kaspa/helpers/TransferSerialize.ts"],"names":[],"mappings":";AAIA,OAAO,KAAK,EAGV,0BAA0B,EAC3B,MAAM,gBAAgB,CAAC;AAExB,wBAAgB,QAAQ,WAEvB;AAED,wBAAgB,gBAAgB,WAE/B;AAqGD,wBAAgB,SAAS,CAAC,WAAW,EAAE,0BAA0B,EAAE,WAAW,EAAE,MAAM;;;EA0BrF"}
1
+ {"version":3,"file":"TransferSerialize.d.ts","sourceRoot":"","sources":["../../../../src/api/kaspa/helpers/TransferSerialize.ts"],"names":[],"mappings":";AAMA,OAAO,KAAK,EAGV,0BAA0B,EAC3B,MAAM,gBAAgB,CAAC;AAExB,wBAAgB,QAAQ,WAEvB;AAED,wBAAgB,gBAAgB,WAE/B;AA2GD,wBAAgB,SAAS,CAAC,WAAW,EAAE,0BAA0B,EAAE,WAAW,EAAE,MAAM;;;EAgCrF"}
@@ -31,7 +31,7 @@ export declare const cancelDeviceInPrompt: (device: Device, expectResponse?: boo
31
31
  };
32
32
  } | {
33
33
  success: boolean;
34
- error: 0 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 200 | 300 | 301 | 302 | 303 | 304 | 305 | 400 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 500 | 600 | 601 | 602 | 603 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 900 | 901 | 902;
34
+ error: 0 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 200 | 300 | 301 | 302 | 303 | 304 | 305 | 400 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 500 | 600 | 601 | 602 | 603 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 829 | 900 | 901 | 902;
35
35
  payload: {
36
36
  message: string;
37
37
  };
@@ -50,7 +50,7 @@ export declare const cancelDeviceWithInitialize: (device: Device) => Promise<{
50
50
  };
51
51
  } | {
52
52
  success: boolean;
53
- error: 0 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 200 | 300 | 301 | 302 | 303 | 304 | 305 | 400 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 500 | 600 | 601 | 602 | 603 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 900 | 901 | 902;
53
+ error: 0 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 200 | 300 | 301 | 302 | 303 | 304 | 305 | 400 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 500 | 600 | 601 | 602 | 603 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 829 | 900 | 901 | 902;
54
54
  payload: {
55
55
  message: string;
56
56
  };
@@ -80,7 +80,7 @@ export declare class DeviceCommands {
80
80
  };
81
81
  } | {
82
82
  success: boolean;
83
- error: 0 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 200 | 300 | 301 | 302 | 303 | 304 | 305 | 400 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 500 | 600 | 601 | 602 | 603 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 900 | 901 | 902;
83
+ error: 0 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 200 | 300 | 301 | 302 | 303 | 304 | 305 | 400 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 500 | 600 | 601 | 602 | 603 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 829 | 900 | 901 | 902;
84
84
  payload: {
85
85
  message: string;
86
86
  };
@@ -99,7 +99,7 @@ export declare class DeviceCommands {
99
99
  };
100
100
  } | {
101
101
  success: boolean;
102
- error: 0 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 200 | 300 | 301 | 302 | 303 | 304 | 305 | 400 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 500 | 600 | 601 | 602 | 603 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 900 | 901 | 902;
102
+ error: 0 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 200 | 300 | 301 | 302 | 303 | 304 | 305 | 400 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 500 | 600 | 601 | 602 | 603 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 829 | 900 | 901 | 902;
103
103
  payload: {
104
104
  message: string;
105
105
  };
package/dist/index.d.ts CHANGED
@@ -3035,7 +3035,7 @@ declare class DeviceCommands {
3035
3035
  };
3036
3036
  } | {
3037
3037
  success: boolean;
3038
- error: 0 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 200 | 300 | 301 | 302 | 303 | 304 | 305 | 400 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 500 | 600 | 601 | 602 | 603 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 900 | 901 | 902;
3038
+ error: 0 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 200 | 300 | 301 | 302 | 303 | 304 | 305 | 400 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 500 | 600 | 601 | 602 | 603 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 829 | 900 | 901 | 902;
3039
3039
  payload: {
3040
3040
  message: string;
3041
3041
  };
@@ -3054,7 +3054,7 @@ declare class DeviceCommands {
3054
3054
  };
3055
3055
  } | {
3056
3056
  success: boolean;
3057
- error: 0 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 200 | 300 | 301 | 302 | 303 | 304 | 305 | 400 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 500 | 600 | 601 | 602 | 603 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 900 | 901 | 902;
3057
+ error: 0 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 200 | 300 | 301 | 302 | 303 | 304 | 305 | 400 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 500 | 600 | 601 | 602 | 603 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 829 | 900 | 901 | 902;
3058
3058
  payload: {
3059
3059
  message: string;
3060
3060
  };
package/dist/index.js CHANGED
@@ -38598,10 +38598,12 @@ function getSigOpCountsHash(transaction, sighashType) {
38598
38598
  return hashWriter.finalize();
38599
38599
  }
38600
38600
  function hashTxOut(hashWriter, output) {
38601
- var _a;
38602
38601
  hashWriter.writeUInt64LE(output.satoshis);
38603
38602
  hashWriter.writeUInt16LE(0);
38604
- hashWriter.writeVarBytes(Buffer.from((_a = output.script) !== null && _a !== void 0 ? _a : '', 'hex'));
38603
+ if (output.script === undefined) {
38604
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Kaspa legacy sighash requires output.script');
38605
+ }
38606
+ hashWriter.writeVarBytes(Buffer.from(output.script, 'hex'));
38605
38607
  }
38606
38608
  function getOutputsHash(transaction, inputNumber, sighashType) {
38607
38609
  if (isSighashNone(sighashType)) {
@@ -38628,6 +38630,9 @@ function serialize(transaction, inputNumber) {
38628
38630
  const input = transaction.inputs[inputNumber];
38629
38631
  hashOutpoint(hashWriter, input);
38630
38632
  hashWriter.writeUInt16LE(0);
38633
+ if (input.output.script === undefined) {
38634
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Kaspa legacy sighash requires input.output.script');
38635
+ }
38631
38636
  hashWriter.writeVarBytes(Buffer.from(input.output.script, 'hex'));
38632
38637
  hashWriter.writeUInt64LE(input.output.satoshis);
38633
38638
  hashWriter.writeUInt64LE(input.sequenceNumber);
@@ -38944,7 +38949,16 @@ class KaspaSignTransaction extends BaseMethod {
38944
38949
  if (!this.supportsStreaming) {
38945
38950
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'KaspaSignTransaction: device firmware uses the streaming protocol; every output requires address or addressN');
38946
38951
  }
38947
- return this.signTxStream(typedCall, response);
38952
+ try {
38953
+ return yield this.signTxStream(typedCall, response);
38954
+ }
38955
+ catch (error) {
38956
+ if (error instanceof hdShared.HardwareError &&
38957
+ String(error.message).toLowerCase().includes('previous transaction id mismatch')) {
38958
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.KaspaPrevTxIdMismatch, String(error.message));
38959
+ }
38960
+ throw error;
38961
+ }
38948
38962
  }
38949
38963
  if (!this.supportsLegacy) {
38950
38964
  throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'KaspaSignTransaction: device chose the legacy protocol but the transaction is not legacy-signable');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-core",
3
- "version": "1.1.32-alpha.4",
3
+ "version": "1.1.34-alpha.0",
4
4
  "description": "Core processes and APIs for communicating with OneKey hardware devices.",
5
5
  "author": "OneKey",
6
6
  "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
@@ -25,8 +25,8 @@
25
25
  "url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
26
26
  },
27
27
  "dependencies": {
28
- "@onekeyfe/hd-shared": "1.1.32-alpha.4",
29
- "@onekeyfe/hd-transport": "1.1.32-alpha.4",
28
+ "@onekeyfe/hd-shared": "1.1.34-alpha.0",
29
+ "@onekeyfe/hd-transport": "1.1.34-alpha.0",
30
30
  "axios": "1.15.2",
31
31
  "bignumber.js": "^9.0.2",
32
32
  "bytebuffer": "^5.0.1",
@@ -44,5 +44,5 @@
44
44
  "@types/w3c-web-usb": "^1.0.10",
45
45
  "@types/web-bluetooth": "^0.0.21"
46
46
  },
47
- "gitHead": "fc3bd904e2d35e9185d34c11460b53d558644009"
47
+ "gitHead": "178851631a3d06dd52c8dd9df24cbaaff7aa6390"
48
48
  }
@@ -476,7 +476,18 @@ export default class KaspaSignTransaction extends BaseMethod<KaspaSignTransactio
476
476
  'KaspaSignTransaction: device firmware uses the streaming protocol; every output requires address or addressN'
477
477
  );
478
478
  }
479
- return this.signTxStream(typedCall, response);
479
+ try {
480
+ return await this.signTxStream(typedCall, response);
481
+ } catch (error) {
482
+ // Device rejected our refTxs; the caller decides whether to sign without them.
483
+ if (
484
+ error instanceof HardwareError &&
485
+ String(error.message).toLowerCase().includes('previous transaction id mismatch')
486
+ ) {
487
+ throw ERRORS.TypedError(HardwareErrorCode.KaspaPrevTxIdMismatch, String(error.message));
488
+ }
489
+ throw error;
490
+ }
480
491
  }
481
492
 
482
493
  // Legacy answer to a streaming-only packet: no prehash material exists.
@@ -1,4 +1,6 @@
1
1
  /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
+ import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
3
+
2
4
  import { SignatureType } from './SignatureType';
3
5
  import { HashWriter } from './HashWriter';
4
6
 
@@ -76,7 +78,13 @@ function getSigOpCountsHash(transaction: KaspaSignTransactionParams, sighashType
76
78
  function hashTxOut(hashWriter: HashWriter, output: KaspaSignOutputParams) {
77
79
  hashWriter.writeUInt64LE(output.satoshis);
78
80
  hashWriter.writeUInt16LE(0); // TODO: USE REAL SCRIPT VERSION
79
- hashWriter.writeVarBytes(Buffer.from(output.script ?? '', 'hex'));
81
+ if (output.script === undefined) {
82
+ throw ERRORS.TypedError(
83
+ HardwareErrorCode.CallMethodInvalidParameter,
84
+ 'Kaspa legacy sighash requires output.script'
85
+ );
86
+ }
87
+ hashWriter.writeVarBytes(Buffer.from(output.script, 'hex'));
80
88
  }
81
89
 
82
90
  function getOutputsHash(
@@ -126,7 +134,13 @@ export function serialize(transaction: KaspaSignTransactionParams, inputNumber:
126
134
  const input = transaction.inputs[inputNumber];
127
135
  hashOutpoint(hashWriter, input);
128
136
  hashWriter.writeUInt16LE(0); // TODO: USE REAL SCRIPT VERSION
129
- hashWriter.writeVarBytes(Buffer.from(input.output.script!, 'hex'));
137
+ if (input.output.script === undefined) {
138
+ throw ERRORS.TypedError(
139
+ HardwareErrorCode.CallMethodInvalidParameter,
140
+ 'Kaspa legacy sighash requires input.output.script'
141
+ );
142
+ }
143
+ hashWriter.writeVarBytes(Buffer.from(input.output.script, 'hex'));
130
144
  hashWriter.writeUInt64LE(input.output.satoshis);
131
145
  hashWriter.writeUInt64LE(input.sequenceNumber);
132
146
  hashWriter.writeUInt8(transaction.sigOpCount ?? 1); // sigOpCount