@onekeyfe/hd-core 1.2.0-alpha.17 → 1.2.0-alpha.18

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/dist/index.js CHANGED
@@ -7564,7 +7564,6 @@ var nested$2 = {
7564
7564
  }
7565
7565
  },
7566
7566
  raw_message: {
7567
- rule: "required",
7568
7567
  type: "bytes",
7569
7568
  id: 2
7570
7569
  },
@@ -7595,6 +7594,42 @@ var nested$2 = {
7595
7594
  options: {
7596
7595
  "default": true
7597
7596
  }
7597
+ },
7598
+ output_count: {
7599
+ type: "uint32",
7600
+ id: 7
7601
+ },
7602
+ version: {
7603
+ type: "uint32",
7604
+ id: 8,
7605
+ options: {
7606
+ "default": 0
7607
+ }
7608
+ },
7609
+ lock_time: {
7610
+ type: "uint64",
7611
+ id: 9,
7612
+ options: {
7613
+ "default": 0
7614
+ }
7615
+ },
7616
+ subnetwork_id: {
7617
+ type: "bytes",
7618
+ id: 10
7619
+ },
7620
+ gas: {
7621
+ type: "uint64",
7622
+ id: 11,
7623
+ options: {
7624
+ "default": 0
7625
+ }
7626
+ },
7627
+ payload_length: {
7628
+ type: "uint32",
7629
+ id: 12,
7630
+ options: {
7631
+ "default": 0
7632
+ }
7598
7633
  }
7599
7634
  }
7600
7635
  },
@@ -7628,6 +7663,249 @@ var nested$2 = {
7628
7663
  }
7629
7664
  }
7630
7665
  },
7666
+ KaspaOutpoint: {
7667
+ fields: {
7668
+ tx_id: {
7669
+ rule: "required",
7670
+ type: "bytes",
7671
+ id: 1
7672
+ },
7673
+ index: {
7674
+ rule: "required",
7675
+ type: "uint32",
7676
+ id: 2
7677
+ }
7678
+ }
7679
+ },
7680
+ KaspaInputScriptType: {
7681
+ values: {
7682
+ KASPA_SPEND_P2PK_SCHNORR: 0,
7683
+ KASPA_SPEND_P2PK_ECDSA: 1
7684
+ }
7685
+ },
7686
+ KaspaOutputScriptType: {
7687
+ values: {
7688
+ KASPA_PAYTOADDRESS: 0,
7689
+ KASPA_PAYTOCHANGE: 1
7690
+ }
7691
+ },
7692
+ KaspaRequestType: {
7693
+ values: {
7694
+ KASPA_TX_INPUT: 0,
7695
+ KASPA_TX_OUTPUT: 1,
7696
+ KASPA_TX_PAYLOAD: 2,
7697
+ KASPA_TX_FINISHED: 3,
7698
+ KASPA_TX_PREV_META: 4
7699
+ }
7700
+ },
7701
+ KaspaTxRequestSignature: {
7702
+ fields: {
7703
+ signature_index: {
7704
+ rule: "required",
7705
+ type: "uint32",
7706
+ id: 1
7707
+ },
7708
+ signature: {
7709
+ rule: "required",
7710
+ type: "bytes",
7711
+ id: 2
7712
+ }
7713
+ }
7714
+ },
7715
+ KaspaTxRequest: {
7716
+ fields: {
7717
+ request_type: {
7718
+ rule: "required",
7719
+ type: "KaspaRequestType",
7720
+ id: 1
7721
+ },
7722
+ request_index: {
7723
+ type: "uint32",
7724
+ id: 2
7725
+ },
7726
+ signature: {
7727
+ type: "KaspaTxRequestSignature",
7728
+ id: 3
7729
+ },
7730
+ request_payload_length: {
7731
+ type: "uint32",
7732
+ id: 4
7733
+ },
7734
+ prev_tx_id: {
7735
+ type: "bytes",
7736
+ id: 5
7737
+ }
7738
+ }
7739
+ },
7740
+ KaspaTxAckInput: {
7741
+ fields: {
7742
+ address_n: {
7743
+ rule: "repeated",
7744
+ type: "uint32",
7745
+ id: 1,
7746
+ options: {
7747
+ packed: false
7748
+ }
7749
+ },
7750
+ previous_outpoint: {
7751
+ rule: "required",
7752
+ type: "KaspaOutpoint",
7753
+ id: 2
7754
+ },
7755
+ amount: {
7756
+ rule: "required",
7757
+ type: "uint64",
7758
+ id: 3
7759
+ },
7760
+ sequence: {
7761
+ rule: "required",
7762
+ type: "uint64",
7763
+ id: 4
7764
+ },
7765
+ sig_op_count: {
7766
+ rule: "required",
7767
+ type: "uint32",
7768
+ id: 5
7769
+ },
7770
+ script_type: {
7771
+ type: "KaspaInputScriptType",
7772
+ id: 6,
7773
+ options: {
7774
+ "default": "KASPA_SPEND_P2PK_SCHNORR"
7775
+ }
7776
+ },
7777
+ use_tweak: {
7778
+ type: "bool",
7779
+ id: 9,
7780
+ options: {
7781
+ "default": true
7782
+ }
7783
+ }
7784
+ }
7785
+ },
7786
+ KaspaTxAckOutput: {
7787
+ fields: {
7788
+ script_type: {
7789
+ type: "KaspaOutputScriptType",
7790
+ id: 1,
7791
+ options: {
7792
+ "default": "KASPA_PAYTOADDRESS"
7793
+ }
7794
+ },
7795
+ amount: {
7796
+ rule: "required",
7797
+ type: "uint64",
7798
+ id: 2
7799
+ },
7800
+ address_n: {
7801
+ rule: "repeated",
7802
+ type: "uint32",
7803
+ id: 3,
7804
+ options: {
7805
+ packed: false
7806
+ }
7807
+ },
7808
+ address: {
7809
+ type: "string",
7810
+ id: 4
7811
+ },
7812
+ scheme: {
7813
+ type: "string",
7814
+ id: 7,
7815
+ options: {
7816
+ "default": "schnorr"
7817
+ }
7818
+ },
7819
+ use_tweak: {
7820
+ type: "bool",
7821
+ id: 8,
7822
+ options: {
7823
+ "default": true
7824
+ }
7825
+ }
7826
+ }
7827
+ },
7828
+ KaspaTxAckPayloadChunk: {
7829
+ fields: {
7830
+ payload_chunk: {
7831
+ rule: "required",
7832
+ type: "bytes",
7833
+ id: 1
7834
+ }
7835
+ }
7836
+ },
7837
+ KaspaTxAckPrevMeta: {
7838
+ fields: {
7839
+ version: {
7840
+ rule: "required",
7841
+ type: "uint32",
7842
+ id: 1
7843
+ },
7844
+ input_count: {
7845
+ rule: "required",
7846
+ type: "uint32",
7847
+ id: 2
7848
+ },
7849
+ output_count: {
7850
+ rule: "required",
7851
+ type: "uint32",
7852
+ id: 3
7853
+ },
7854
+ lock_time: {
7855
+ rule: "required",
7856
+ type: "uint64",
7857
+ id: 4
7858
+ },
7859
+ subnetwork_id: {
7860
+ rule: "required",
7861
+ type: "bytes",
7862
+ id: 5
7863
+ },
7864
+ gas: {
7865
+ rule: "required",
7866
+ type: "uint64",
7867
+ id: 6
7868
+ },
7869
+ payload_length: {
7870
+ rule: "required",
7871
+ type: "uint32",
7872
+ id: 7
7873
+ }
7874
+ }
7875
+ },
7876
+ KaspaTxAckPrevInput: {
7877
+ fields: {
7878
+ previous_outpoint: {
7879
+ rule: "required",
7880
+ type: "KaspaOutpoint",
7881
+ id: 1
7882
+ },
7883
+ sequence: {
7884
+ rule: "required",
7885
+ type: "uint64",
7886
+ id: 2
7887
+ }
7888
+ }
7889
+ },
7890
+ KaspaTxAckPrevOutput: {
7891
+ fields: {
7892
+ amount: {
7893
+ rule: "required",
7894
+ type: "uint64",
7895
+ id: 1
7896
+ },
7897
+ script_version: {
7898
+ rule: "required",
7899
+ type: "uint32",
7900
+ id: 2
7901
+ },
7902
+ script_public_key: {
7903
+ rule: "required",
7904
+ type: "bytes",
7905
+ id: 3
7906
+ }
7907
+ }
7908
+ },
7631
7909
  KaspaSignedTx: {
7632
7910
  fields: {
7633
7911
  signature: {
@@ -14075,6 +14353,13 @@ var nested$2 = {
14075
14353
  MessageType_KaspaSignedTx: 11303,
14076
14354
  MessageType_KaspaTxInputRequest: 11304,
14077
14355
  MessageType_KaspaTxInputAck: 11305,
14356
+ MessageType_KaspaTxRequest: 11306,
14357
+ MessageType_KaspaTxAckInput: 11307,
14358
+ MessageType_KaspaTxAckOutput: 11308,
14359
+ MessageType_KaspaTxAckPayloadChunk: 11309,
14360
+ MessageType_KaspaTxAckPrevMeta: 11310,
14361
+ MessageType_KaspaTxAckPrevInput: 11311,
14362
+ MessageType_KaspaTxAckPrevOutput: 11312,
14078
14363
  MessageType_NexaGetAddress: 11400,
14079
14364
  MessageType_NexaAddress: 11401,
14080
14365
  MessageType_NexaSignTx: 11402,
@@ -56027,6 +56312,9 @@ function getSigOpCountsHash(transaction, sighashType) {
56027
56312
  function hashTxOut(hashWriter, output) {
56028
56313
  hashWriter.writeUInt64LE(output.satoshis);
56029
56314
  hashWriter.writeUInt16LE(0);
56315
+ if (output.script === undefined) {
56316
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Kaspa legacy sighash requires output.script');
56317
+ }
56030
56318
  hashWriter.writeVarBytes(Buffer.from(output.script, 'hex'));
56031
56319
  }
56032
56320
  function getOutputsHash(transaction, inputNumber, sighashType) {
@@ -56054,6 +56342,9 @@ function serialize(transaction, inputNumber) {
56054
56342
  const input = transaction.inputs[inputNumber];
56055
56343
  hashOutpoint(hashWriter, input);
56056
56344
  hashWriter.writeUInt16LE(0);
56345
+ if (input.output.script === undefined) {
56346
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'Kaspa legacy sighash requires input.output.script');
56347
+ }
56057
56348
  hashWriter.writeVarBytes(Buffer.from(input.output.script, 'hex'));
56058
56349
  hashWriter.writeUInt64LE(input.output.satoshis);
56059
56350
  hashWriter.writeUInt64LE(input.sequenceNumber);
@@ -56070,25 +56361,31 @@ function serialize(transaction, inputNumber) {
56070
56361
  };
56071
56362
  }
56072
56363
 
56364
+ const P2PK_SCRIPT = /^(20[0-9a-f]{64}ac|21[0-9a-f]{66}ab)$/i;
56365
+ const isStreamableScript = (script) => !script || P2PK_SCRIPT.test(script);
56073
56366
  class KaspaSignTransaction extends BaseMethod {
56074
56367
  constructor() {
56075
56368
  super(...arguments);
56076
56369
  this.hasBundle = false;
56370
+ this.supportsLegacy = false;
56371
+ this.supportsStreaming = false;
56077
56372
  }
56078
56373
  init() {
56079
- var _a, _b, _c, _d, _e;
56374
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
56080
56375
  this.checkDeviceId = true;
56081
56376
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
56082
56377
  this.allowUsePreInitialize = true;
56083
56378
  const payload = this.payload;
56084
56379
  validateParams(payload, [
56085
56380
  { name: 'version', type: 'number' },
56086
- { name: 'sigHashType', type: 'number', required: true },
56381
+ { name: 'sigHashType', type: 'number' },
56087
56382
  { name: 'inputs', type: 'array', required: true },
56088
56383
  { name: 'outputs', type: 'array', required: true },
56089
56384
  { name: 'lockTime', required: true },
56090
56385
  { name: 'sigOpCount', type: 'number' },
56091
56386
  { name: 'subNetworkID', type: 'string' },
56387
+ { name: 'payload', type: 'hexString' },
56388
+ { name: 'refTxs', type: 'array', allowEmpty: true },
56092
56389
  { name: 'useTweak', type: 'boolean' },
56093
56390
  ]);
56094
56391
  const inputs = payload.inputs.map(input => {
@@ -56099,20 +56396,47 @@ class KaspaSignTransaction extends BaseMethod {
56099
56396
  { name: 'outputIndex', type: 'number', required: true },
56100
56397
  { name: 'sequenceNumber', required: true },
56101
56398
  ]);
56399
+ validateParams(input.output, [{ name: 'satoshis', required: true }]);
56102
56400
  const addressN = validatePath(input.path, 3);
56103
56401
  return Object.assign(Object.assign({}, input), { path: addressN, sigOpCount: (_a = input.sigOpCount) !== null && _a !== void 0 ? _a : 1 });
56104
56402
  });
56403
+ (_a = payload.refTxs) === null || _a === void 0 ? void 0 : _a.forEach(refTx => {
56404
+ validateParams(refTx, [
56405
+ { name: 'txId', type: 'string', required: true },
56406
+ { name: 'version', type: 'number', required: true },
56407
+ { name: 'inputs', type: 'array', required: true, allowEmpty: true },
56408
+ { name: 'outputs', type: 'array', required: true, allowEmpty: true },
56409
+ { name: 'payload', type: 'hexString' },
56410
+ ]);
56411
+ });
56105
56412
  const outputs = payload.outputs.map(output => {
56106
56413
  var _a;
56107
56414
  validateParams(output, [
56108
56415
  { name: 'satoshis', required: true },
56109
- { name: 'script', type: 'string', required: true },
56416
+ { name: 'address', type: 'string' },
56417
+ { name: 'script', type: 'string' },
56110
56418
  { name: 'scriptVersion', type: 'number' },
56111
56419
  ]);
56112
- return Object.assign(Object.assign({}, output), { scriptVersion: (_a = output.scriptVersion) !== null && _a !== void 0 ? _a : 0 });
56420
+ return Object.assign(Object.assign({}, output), { addressN: output.addressN ? validatePath(output.addressN, 3) : undefined, scriptVersion: (_a = output.scriptVersion) !== null && _a !== void 0 ? _a : 0 });
56113
56421
  });
56114
56422
  this.params = Object.assign(Object.assign({}, payload), { inputs,
56115
- outputs, scheme: (_a = payload.scheme) !== null && _a !== void 0 ? _a : 'schnorr', prefix: (_b = payload.prefix) !== null && _b !== void 0 ? _b : 'kaspa', sigHashType: (_c = payload.sigHashType) !== null && _c !== void 0 ? _c : SignatureType.SIGHASH_ALL | SignatureType.SIGHASH_FORKID, sigOpCount: (_d = payload.sigOpCount) !== null && _d !== void 0 ? _d : 1, subNetworkID: (_e = payload.subNetworkID) !== null && _e !== void 0 ? _e : utils.bytesToHex(zeroSubnetworkID()), useTweak: payload.useTweak });
56423
+ outputs, scheme: (_b = payload.scheme) !== null && _b !== void 0 ? _b : 'schnorr', prefix: (_c = payload.prefix) !== null && _c !== void 0 ? _c : 'kaspa', sigHashType: (_d = payload.sigHashType) !== null && _d !== void 0 ? _d : SignatureType.SIGHASH_ALL | SignatureType.SIGHASH_FORKID, sigOpCount: (_e = payload.sigOpCount) !== null && _e !== void 0 ? _e : 1, subNetworkID: (_f = payload.subNetworkID) !== null && _f !== void 0 ? _f : utils.bytesToHex(zeroSubnetworkID()), gas: (_g = payload.gas) !== null && _g !== void 0 ? _g : 0, useTweak: payload.useTweak });
56424
+ this.supportsLegacy =
56425
+ this.params.outputs.every(output => !!output.script) &&
56426
+ this.params.inputs.every(input => !!input.output.script) &&
56427
+ !this.params.payload &&
56428
+ Number((_h = this.params.gas) !== null && _h !== void 0 ? _h : 0) === 0 &&
56429
+ /^0*$/.test((_j = this.params.subNetworkID) !== null && _j !== void 0 ? _j : '');
56430
+ const isDefaultSigHashType = this.params.sigHashType === SignatureType.SIGHASH_ALL ||
56431
+ this.params.sigHashType === (SignatureType.SIGHASH_ALL | SignatureType.SIGHASH_FORKID);
56432
+ this.supportsStreaming =
56433
+ isDefaultSigHashType &&
56434
+ this.params.outputs.every(output => !!output.address || !!output.addressN) &&
56435
+ this.params.inputs.every(input => isStreamableScript(input.output.script)) &&
56436
+ this.params.outputs.every(output => isStreamableScript(output.script));
56437
+ if (!this.supportsLegacy && !this.supportsStreaming) {
56438
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'KaspaSignTransaction: outputs require either address/addressN (streaming protocol) or script (legacy protocol)');
56439
+ }
56116
56440
  }
56117
56441
  getVersionRange() {
56118
56442
  return {
@@ -56161,23 +56485,197 @@ class KaspaSignTransaction extends BaseMethod {
56161
56485
  return signature;
56162
56486
  });
56163
56487
  }
56488
+ ackPrevRequest(typedCall, request, requestIndex) {
56489
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
56490
+ return __awaiter(this, void 0, void 0, function* () {
56491
+ const prevTxId = ((_a = request.prev_tx_id) !== null && _a !== void 0 ? _a : '').toLowerCase();
56492
+ const refTx = ((_b = this.params.refTxs) !== null && _b !== void 0 ? _b : []).find(tx => tx.txId.toLowerCase() === prevTxId);
56493
+ if (!refTx) {
56494
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `KaspaSignTransaction: device requested previous transaction ${prevTxId || '(unknown)'}; provide it via refTxs`);
56495
+ }
56496
+ const requestType = request.request_type;
56497
+ if (requestType === 'KASPA_TX_PREV_META') {
56498
+ return typedCall('KaspaTxAckPrevMeta', 'KaspaTxRequest', {
56499
+ version: refTx.version,
56500
+ input_count: refTx.inputs.length,
56501
+ output_count: refTx.outputs.length,
56502
+ lock_time: ((_c = refTx.lockTime) !== null && _c !== void 0 ? _c : 0),
56503
+ subnetwork_id: (_d = refTx.subNetworkID) !== null && _d !== void 0 ? _d : utils.bytesToHex(zeroSubnetworkID()),
56504
+ gas: ((_e = refTx.gas) !== null && _e !== void 0 ? _e : 0),
56505
+ payload_length: ((_f = refTx.payload) !== null && _f !== void 0 ? _f : '').length / 2,
56506
+ });
56507
+ }
56508
+ if (requestType === 'KASPA_TX_INPUT') {
56509
+ const input = refTx.inputs[requestIndex];
56510
+ if (!input) {
56511
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `KaspaSignTransaction: device requested input ${requestIndex} of previous tx out of range`);
56512
+ }
56513
+ return typedCall('KaspaTxAckPrevInput', 'KaspaTxRequest', {
56514
+ previous_outpoint: {
56515
+ tx_id: input.prevTxId,
56516
+ index: input.outputIndex,
56517
+ },
56518
+ sequence: input.sequenceNumber,
56519
+ });
56520
+ }
56521
+ if (requestType === 'KASPA_TX_OUTPUT') {
56522
+ const output = refTx.outputs[requestIndex];
56523
+ if (!output) {
56524
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `KaspaSignTransaction: device requested output ${requestIndex} of previous tx out of range`);
56525
+ }
56526
+ return typedCall('KaspaTxAckPrevOutput', 'KaspaTxRequest', {
56527
+ amount: output.satoshis,
56528
+ script_version: (_g = output.scriptVersion) !== null && _g !== void 0 ? _g : 0,
56529
+ script_public_key: output.script,
56530
+ });
56531
+ }
56532
+ if (requestType === 'KASPA_TX_PAYLOAD') {
56533
+ const payloadHex = (_h = refTx.payload) !== null && _h !== void 0 ? _h : '';
56534
+ const payloadLength = payloadHex.length / 2;
56535
+ const length = (_j = request.request_payload_length) !== null && _j !== void 0 ? _j : payloadLength - requestIndex;
56536
+ return typedCall('KaspaTxAckPayloadChunk', 'KaspaTxRequest', {
56537
+ payload_chunk: payloadHex.substring(requestIndex * 2, (requestIndex + length) * 2),
56538
+ });
56539
+ }
56540
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `KaspaSignTransaction: unknown previous-tx request type ${requestType !== null && requestType !== void 0 ? requestType : 'undefined'}`);
56541
+ });
56542
+ }
56543
+ signTxStream(typedCall, firstResponse) {
56544
+ var _a, _b, _c, _d, _e;
56545
+ return __awaiter(this, void 0, void 0, function* () {
56546
+ const { params } = this;
56547
+ const signatures = [];
56548
+ const inputScriptType = params.scheme === 'ecdsa' ? 'KASPA_SPEND_P2PK_ECDSA' : 'KASPA_SPEND_P2PK_SCHNORR';
56549
+ const saveSignature = (signature) => {
56550
+ if (signature && typeof signature.signature_index === 'number' && signature.signature) {
56551
+ signatures[signature.signature_index] = {
56552
+ index: signature.signature_index,
56553
+ signature: signature.signature,
56554
+ };
56555
+ }
56556
+ };
56557
+ const payloadHex = (_a = params.payload) !== null && _a !== void 0 ? _a : '';
56558
+ const payloadLength = payloadHex.length / 2;
56559
+ let response = firstResponse;
56560
+ while (true) {
56561
+ const request = response.message;
56562
+ saveSignature(request.signature);
56563
+ const requestType = request.request_type;
56564
+ if (requestType === 'KASPA_TX_FINISHED') {
56565
+ break;
56566
+ }
56567
+ const requestIndex = (_b = request.request_index) !== null && _b !== void 0 ? _b : 0;
56568
+ if (request.prev_tx_id || requestType === 'KASPA_TX_PREV_META') {
56569
+ response = yield this.ackPrevRequest(typedCall, request, requestIndex);
56570
+ }
56571
+ else if (requestType === 'KASPA_TX_INPUT') {
56572
+ const input = params.inputs[requestIndex];
56573
+ if (!input) {
56574
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `KaspaSignTransaction: device requested input ${requestIndex} out of range`);
56575
+ }
56576
+ response = yield typedCall('KaspaTxAckInput', 'KaspaTxRequest', {
56577
+ address_n: input.path,
56578
+ previous_outpoint: {
56579
+ tx_id: input.prevTxId,
56580
+ index: input.outputIndex,
56581
+ },
56582
+ amount: input.output.satoshis,
56583
+ sequence: input.sequenceNumber,
56584
+ sig_op_count: (_c = input.sigOpCount) !== null && _c !== void 0 ? _c : 1,
56585
+ script_type: inputScriptType,
56586
+ use_tweak: params.useTweak,
56587
+ });
56588
+ }
56589
+ else if (requestType === 'KASPA_TX_OUTPUT') {
56590
+ const output = params.outputs[requestIndex];
56591
+ if (!output) {
56592
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `KaspaSignTransaction: device requested output ${requestIndex} out of range`);
56593
+ }
56594
+ const isChange = !!output.addressN;
56595
+ response = yield typedCall('KaspaTxAckOutput', 'KaspaTxRequest', {
56596
+ script_type: isChange ? 'KASPA_PAYTOCHANGE' : 'KASPA_PAYTOADDRESS',
56597
+ amount: output.satoshis,
56598
+ address_n: (_d = output.addressN) !== null && _d !== void 0 ? _d : [],
56599
+ address: output.address,
56600
+ scheme: params.scheme,
56601
+ use_tweak: params.useTweak,
56602
+ });
56603
+ }
56604
+ else if (requestType === 'KASPA_TX_PAYLOAD') {
56605
+ const offset = requestIndex;
56606
+ const length = (_e = request.request_payload_length) !== null && _e !== void 0 ? _e : payloadLength - offset;
56607
+ const chunk = payloadHex.substring(offset * 2, (offset + length) * 2);
56608
+ response = yield typedCall('KaspaTxAckPayloadChunk', 'KaspaTxRequest', {
56609
+ payload_chunk: chunk,
56610
+ });
56611
+ }
56612
+ else {
56613
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `KaspaSignTransaction: unknown request type ${requestType !== null && requestType !== void 0 ? requestType : 'undefined'}`);
56614
+ }
56615
+ }
56616
+ const collected = signatures.filter(Boolean);
56617
+ if (collected.length !== params.inputs.length) {
56618
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `KaspaSignTransaction: expected ${params.inputs.length} signatures, received ${collected.length}`);
56619
+ }
56620
+ return collected;
56621
+ });
56622
+ }
56164
56623
  run() {
56624
+ var _a, _b, _c;
56165
56625
  return __awaiter(this, void 0, void 0, function* () {
56166
56626
  this.checkFeatureVersionLimit(() => this.params.useTweak === false, () => this.getUseTweakVersionRange(), {
56167
56627
  strictCheckDeviceSupport: true,
56168
56628
  });
56169
- const { raw: rawMessage } = serialize(this.params, 0);
56170
- const input = this.params.inputs[0];
56171
56629
  const { device, params } = this;
56172
- const response = yield device.commands.typedCall('KaspaSignTx', ['KaspaTxInputRequest', 'KaspaSignedTx'], {
56173
- address_n: validatePath(input.path, 3),
56174
- raw_message: utils.bytesToHex(rawMessage),
56175
- scheme: params.scheme,
56176
- prefix: params.prefix,
56177
- input_count: params.inputs.length,
56178
- use_tweak: params.useTweak,
56179
- });
56180
- return this.processTxRequest(device.commands.typedCall.bind(device.commands), response, 0, []);
56630
+ const payloadHex = (_a = params.payload) !== null && _a !== void 0 ? _a : '';
56631
+ const hasRefTxs = ((_c = (_b = params.refTxs) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0) > 0;
56632
+ const streamingReady = this.supportsStreaming && (hasRefTxs || !this.supportsLegacy);
56633
+ const streamingFields = streamingReady
56634
+ ? {
56635
+ output_count: params.outputs.length,
56636
+ version: params.version,
56637
+ lock_time: params.lockTime,
56638
+ subnetwork_id: params.subNetworkID,
56639
+ gas: params.gas,
56640
+ payload_length: payloadHex.length / 2,
56641
+ }
56642
+ : {};
56643
+ const legacyFields = this.supportsLegacy
56644
+ ? { raw_message: utils.bytesToHex(serialize(params, 0).raw) }
56645
+ : {};
56646
+ let response;
56647
+ try {
56648
+ response = yield device.commands.typedCall('KaspaSignTx', ['KaspaTxRequest', 'KaspaTxInputRequest', 'KaspaSignedTx'], Object.assign(Object.assign({ address_n: params.inputs[0].path, scheme: params.scheme, prefix: params.prefix, input_count: params.inputs.length, use_tweak: params.useTweak }, streamingFields), legacyFields));
56649
+ }
56650
+ catch (error) {
56651
+ if (!this.supportsLegacy &&
56652
+ error instanceof hdShared.HardwareError &&
56653
+ error.errorCode === hdShared.HardwareErrorCode.RuntimeError &&
56654
+ String(error.message).includes('Failure_DataError')) {
56655
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodNeedUpgradeFirmware, 'KaspaSignTransaction: this transaction requires firmware with Kaspa streaming support');
56656
+ }
56657
+ throw error;
56658
+ }
56659
+ const typedCall = device.commands.typedCall.bind(device.commands);
56660
+ if (response.type === 'KaspaTxRequest') {
56661
+ if (!this.supportsStreaming) {
56662
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'KaspaSignTransaction: device firmware uses the streaming protocol; every output requires address or addressN');
56663
+ }
56664
+ try {
56665
+ return yield this.signTxStream(typedCall, response);
56666
+ }
56667
+ catch (error) {
56668
+ if (error instanceof hdShared.HardwareError &&
56669
+ String(error.message).toLowerCase().includes('previous transaction id mismatch')) {
56670
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.KaspaPrevTxIdMismatch, String(error.message));
56671
+ }
56672
+ throw error;
56673
+ }
56674
+ }
56675
+ if (!this.supportsLegacy) {
56676
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'KaspaSignTransaction: device chose the legacy protocol but the transaction is not legacy-signable');
56677
+ }
56678
+ return this.processTxRequest(typedCall, response, 0, []);
56181
56679
  });
56182
56680
  }
56183
56681
  }
@@ -11,14 +11,36 @@ export type KaspaSignInputParams = {
11
11
  sequenceNumber: number | string;
12
12
  output: {
13
13
  satoshis: number | string;
14
- script: string;
14
+ script?: string;
15
15
  };
16
16
  sigOpCount?: number;
17
17
  };
18
18
  export type KaspaSignOutputParams = {
19
19
  satoshis: number | string;
20
+ address?: string;
21
+ addressN?: string | number[];
22
+ script?: string;
23
+ scriptVersion?: number;
24
+ };
25
+ export type KaspaRefTransactionInput = {
26
+ prevTxId: string;
27
+ outputIndex: number;
28
+ sequenceNumber: number | string;
29
+ };
30
+ export type KaspaRefTransactionOutput = {
31
+ satoshis: number | string;
32
+ scriptVersion?: number;
20
33
  script: string;
21
- scriptVersion: number;
34
+ };
35
+ export type KaspaRefTransaction = {
36
+ txId: string;
37
+ version: number;
38
+ inputs: KaspaRefTransactionInput[];
39
+ outputs: KaspaRefTransactionOutput[];
40
+ lockTime?: number | string;
41
+ subNetworkID?: string;
42
+ gas?: number | string;
43
+ payload?: string;
22
44
  };
23
45
  export type KaspaSignTransactionParams = {
24
46
  version: number;
@@ -28,6 +50,9 @@ export type KaspaSignTransactionParams = {
28
50
  sigHashType?: SignatureType;
29
51
  sigOpCount?: number;
30
52
  subNetworkID?: string;
53
+ payload?: string;
54
+ gas?: number | string;
55
+ refTxs?: KaspaRefTransaction[];
31
56
  scheme?: string;
32
57
  prefix?: string;
33
58
  useTweak?: boolean;
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