@onekeyfe/hd-core 1.1.31 → 1.1.32-alpha.4
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/__tests__/kaspaSignTransaction.test.ts +531 -0
- package/dist/api/kaspa/KaspaSignTransaction.d.ts +5 -1
- package/dist/api/kaspa/KaspaSignTransaction.d.ts.map +1 -1
- package/dist/index.d.ts +28 -3
- package/dist/index.js +502 -18
- package/dist/types/api/kaspaSignTransaction.d.ts +27 -2
- package/dist/types/api/kaspaSignTransaction.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/kaspa/KaspaSignTransaction.ts +330 -21
- package/src/api/kaspa/helpers/TransferSerialize.ts +2 -2
- package/src/data/messages/messages.json +286 -1
- package/src/types/api/kaspaSignTransaction.ts +40 -2
package/dist/index.js
CHANGED
|
@@ -7552,7 +7552,6 @@ var nested$1 = {
|
|
|
7552
7552
|
}
|
|
7553
7553
|
},
|
|
7554
7554
|
raw_message: {
|
|
7555
|
-
rule: "required",
|
|
7556
7555
|
type: "bytes",
|
|
7557
7556
|
id: 2
|
|
7558
7557
|
},
|
|
@@ -7583,6 +7582,42 @@ var nested$1 = {
|
|
|
7583
7582
|
options: {
|
|
7584
7583
|
"default": true
|
|
7585
7584
|
}
|
|
7585
|
+
},
|
|
7586
|
+
output_count: {
|
|
7587
|
+
type: "uint32",
|
|
7588
|
+
id: 7
|
|
7589
|
+
},
|
|
7590
|
+
version: {
|
|
7591
|
+
type: "uint32",
|
|
7592
|
+
id: 8,
|
|
7593
|
+
options: {
|
|
7594
|
+
"default": 0
|
|
7595
|
+
}
|
|
7596
|
+
},
|
|
7597
|
+
lock_time: {
|
|
7598
|
+
type: "uint64",
|
|
7599
|
+
id: 9,
|
|
7600
|
+
options: {
|
|
7601
|
+
"default": 0
|
|
7602
|
+
}
|
|
7603
|
+
},
|
|
7604
|
+
subnetwork_id: {
|
|
7605
|
+
type: "bytes",
|
|
7606
|
+
id: 10
|
|
7607
|
+
},
|
|
7608
|
+
gas: {
|
|
7609
|
+
type: "uint64",
|
|
7610
|
+
id: 11,
|
|
7611
|
+
options: {
|
|
7612
|
+
"default": 0
|
|
7613
|
+
}
|
|
7614
|
+
},
|
|
7615
|
+
payload_length: {
|
|
7616
|
+
type: "uint32",
|
|
7617
|
+
id: 12,
|
|
7618
|
+
options: {
|
|
7619
|
+
"default": 0
|
|
7620
|
+
}
|
|
7586
7621
|
}
|
|
7587
7622
|
}
|
|
7588
7623
|
},
|
|
@@ -7616,6 +7651,249 @@ var nested$1 = {
|
|
|
7616
7651
|
}
|
|
7617
7652
|
}
|
|
7618
7653
|
},
|
|
7654
|
+
KaspaOutpoint: {
|
|
7655
|
+
fields: {
|
|
7656
|
+
tx_id: {
|
|
7657
|
+
rule: "required",
|
|
7658
|
+
type: "bytes",
|
|
7659
|
+
id: 1
|
|
7660
|
+
},
|
|
7661
|
+
index: {
|
|
7662
|
+
rule: "required",
|
|
7663
|
+
type: "uint32",
|
|
7664
|
+
id: 2
|
|
7665
|
+
}
|
|
7666
|
+
}
|
|
7667
|
+
},
|
|
7668
|
+
KaspaInputScriptType: {
|
|
7669
|
+
values: {
|
|
7670
|
+
KASPA_SPEND_P2PK_SCHNORR: 0,
|
|
7671
|
+
KASPA_SPEND_P2PK_ECDSA: 1
|
|
7672
|
+
}
|
|
7673
|
+
},
|
|
7674
|
+
KaspaOutputScriptType: {
|
|
7675
|
+
values: {
|
|
7676
|
+
KASPA_PAYTOADDRESS: 0,
|
|
7677
|
+
KASPA_PAYTOCHANGE: 1
|
|
7678
|
+
}
|
|
7679
|
+
},
|
|
7680
|
+
KaspaRequestType: {
|
|
7681
|
+
values: {
|
|
7682
|
+
KASPA_TX_INPUT: 0,
|
|
7683
|
+
KASPA_TX_OUTPUT: 1,
|
|
7684
|
+
KASPA_TX_PAYLOAD: 2,
|
|
7685
|
+
KASPA_TX_FINISHED: 3,
|
|
7686
|
+
KASPA_TX_PREV_META: 4
|
|
7687
|
+
}
|
|
7688
|
+
},
|
|
7689
|
+
KaspaTxRequestSignature: {
|
|
7690
|
+
fields: {
|
|
7691
|
+
signature_index: {
|
|
7692
|
+
rule: "required",
|
|
7693
|
+
type: "uint32",
|
|
7694
|
+
id: 1
|
|
7695
|
+
},
|
|
7696
|
+
signature: {
|
|
7697
|
+
rule: "required",
|
|
7698
|
+
type: "bytes",
|
|
7699
|
+
id: 2
|
|
7700
|
+
}
|
|
7701
|
+
}
|
|
7702
|
+
},
|
|
7703
|
+
KaspaTxRequest: {
|
|
7704
|
+
fields: {
|
|
7705
|
+
request_type: {
|
|
7706
|
+
rule: "required",
|
|
7707
|
+
type: "KaspaRequestType",
|
|
7708
|
+
id: 1
|
|
7709
|
+
},
|
|
7710
|
+
request_index: {
|
|
7711
|
+
type: "uint32",
|
|
7712
|
+
id: 2
|
|
7713
|
+
},
|
|
7714
|
+
signature: {
|
|
7715
|
+
type: "KaspaTxRequestSignature",
|
|
7716
|
+
id: 3
|
|
7717
|
+
},
|
|
7718
|
+
request_payload_length: {
|
|
7719
|
+
type: "uint32",
|
|
7720
|
+
id: 4
|
|
7721
|
+
},
|
|
7722
|
+
prev_tx_id: {
|
|
7723
|
+
type: "bytes",
|
|
7724
|
+
id: 5
|
|
7725
|
+
}
|
|
7726
|
+
}
|
|
7727
|
+
},
|
|
7728
|
+
KaspaTxAckInput: {
|
|
7729
|
+
fields: {
|
|
7730
|
+
address_n: {
|
|
7731
|
+
rule: "repeated",
|
|
7732
|
+
type: "uint32",
|
|
7733
|
+
id: 1,
|
|
7734
|
+
options: {
|
|
7735
|
+
packed: false
|
|
7736
|
+
}
|
|
7737
|
+
},
|
|
7738
|
+
previous_outpoint: {
|
|
7739
|
+
rule: "required",
|
|
7740
|
+
type: "KaspaOutpoint",
|
|
7741
|
+
id: 2
|
|
7742
|
+
},
|
|
7743
|
+
amount: {
|
|
7744
|
+
rule: "required",
|
|
7745
|
+
type: "uint64",
|
|
7746
|
+
id: 3
|
|
7747
|
+
},
|
|
7748
|
+
sequence: {
|
|
7749
|
+
rule: "required",
|
|
7750
|
+
type: "uint64",
|
|
7751
|
+
id: 4
|
|
7752
|
+
},
|
|
7753
|
+
sig_op_count: {
|
|
7754
|
+
rule: "required",
|
|
7755
|
+
type: "uint32",
|
|
7756
|
+
id: 5
|
|
7757
|
+
},
|
|
7758
|
+
script_type: {
|
|
7759
|
+
type: "KaspaInputScriptType",
|
|
7760
|
+
id: 6,
|
|
7761
|
+
options: {
|
|
7762
|
+
"default": "KASPA_SPEND_P2PK_SCHNORR"
|
|
7763
|
+
}
|
|
7764
|
+
},
|
|
7765
|
+
use_tweak: {
|
|
7766
|
+
type: "bool",
|
|
7767
|
+
id: 9,
|
|
7768
|
+
options: {
|
|
7769
|
+
"default": true
|
|
7770
|
+
}
|
|
7771
|
+
}
|
|
7772
|
+
}
|
|
7773
|
+
},
|
|
7774
|
+
KaspaTxAckOutput: {
|
|
7775
|
+
fields: {
|
|
7776
|
+
script_type: {
|
|
7777
|
+
type: "KaspaOutputScriptType",
|
|
7778
|
+
id: 1,
|
|
7779
|
+
options: {
|
|
7780
|
+
"default": "KASPA_PAYTOADDRESS"
|
|
7781
|
+
}
|
|
7782
|
+
},
|
|
7783
|
+
amount: {
|
|
7784
|
+
rule: "required",
|
|
7785
|
+
type: "uint64",
|
|
7786
|
+
id: 2
|
|
7787
|
+
},
|
|
7788
|
+
address_n: {
|
|
7789
|
+
rule: "repeated",
|
|
7790
|
+
type: "uint32",
|
|
7791
|
+
id: 3,
|
|
7792
|
+
options: {
|
|
7793
|
+
packed: false
|
|
7794
|
+
}
|
|
7795
|
+
},
|
|
7796
|
+
address: {
|
|
7797
|
+
type: "string",
|
|
7798
|
+
id: 4
|
|
7799
|
+
},
|
|
7800
|
+
scheme: {
|
|
7801
|
+
type: "string",
|
|
7802
|
+
id: 7,
|
|
7803
|
+
options: {
|
|
7804
|
+
"default": "schnorr"
|
|
7805
|
+
}
|
|
7806
|
+
},
|
|
7807
|
+
use_tweak: {
|
|
7808
|
+
type: "bool",
|
|
7809
|
+
id: 8,
|
|
7810
|
+
options: {
|
|
7811
|
+
"default": true
|
|
7812
|
+
}
|
|
7813
|
+
}
|
|
7814
|
+
}
|
|
7815
|
+
},
|
|
7816
|
+
KaspaTxAckPayloadChunk: {
|
|
7817
|
+
fields: {
|
|
7818
|
+
payload_chunk: {
|
|
7819
|
+
rule: "required",
|
|
7820
|
+
type: "bytes",
|
|
7821
|
+
id: 1
|
|
7822
|
+
}
|
|
7823
|
+
}
|
|
7824
|
+
},
|
|
7825
|
+
KaspaTxAckPrevMeta: {
|
|
7826
|
+
fields: {
|
|
7827
|
+
version: {
|
|
7828
|
+
rule: "required",
|
|
7829
|
+
type: "uint32",
|
|
7830
|
+
id: 1
|
|
7831
|
+
},
|
|
7832
|
+
input_count: {
|
|
7833
|
+
rule: "required",
|
|
7834
|
+
type: "uint32",
|
|
7835
|
+
id: 2
|
|
7836
|
+
},
|
|
7837
|
+
output_count: {
|
|
7838
|
+
rule: "required",
|
|
7839
|
+
type: "uint32",
|
|
7840
|
+
id: 3
|
|
7841
|
+
},
|
|
7842
|
+
lock_time: {
|
|
7843
|
+
rule: "required",
|
|
7844
|
+
type: "uint64",
|
|
7845
|
+
id: 4
|
|
7846
|
+
},
|
|
7847
|
+
subnetwork_id: {
|
|
7848
|
+
rule: "required",
|
|
7849
|
+
type: "bytes",
|
|
7850
|
+
id: 5
|
|
7851
|
+
},
|
|
7852
|
+
gas: {
|
|
7853
|
+
rule: "required",
|
|
7854
|
+
type: "uint64",
|
|
7855
|
+
id: 6
|
|
7856
|
+
},
|
|
7857
|
+
payload_length: {
|
|
7858
|
+
rule: "required",
|
|
7859
|
+
type: "uint32",
|
|
7860
|
+
id: 7
|
|
7861
|
+
}
|
|
7862
|
+
}
|
|
7863
|
+
},
|
|
7864
|
+
KaspaTxAckPrevInput: {
|
|
7865
|
+
fields: {
|
|
7866
|
+
previous_outpoint: {
|
|
7867
|
+
rule: "required",
|
|
7868
|
+
type: "KaspaOutpoint",
|
|
7869
|
+
id: 1
|
|
7870
|
+
},
|
|
7871
|
+
sequence: {
|
|
7872
|
+
rule: "required",
|
|
7873
|
+
type: "uint64",
|
|
7874
|
+
id: 2
|
|
7875
|
+
}
|
|
7876
|
+
}
|
|
7877
|
+
},
|
|
7878
|
+
KaspaTxAckPrevOutput: {
|
|
7879
|
+
fields: {
|
|
7880
|
+
amount: {
|
|
7881
|
+
rule: "required",
|
|
7882
|
+
type: "uint64",
|
|
7883
|
+
id: 1
|
|
7884
|
+
},
|
|
7885
|
+
script_version: {
|
|
7886
|
+
rule: "required",
|
|
7887
|
+
type: "uint32",
|
|
7888
|
+
id: 2
|
|
7889
|
+
},
|
|
7890
|
+
script_public_key: {
|
|
7891
|
+
rule: "required",
|
|
7892
|
+
type: "bytes",
|
|
7893
|
+
id: 3
|
|
7894
|
+
}
|
|
7895
|
+
}
|
|
7896
|
+
},
|
|
7619
7897
|
KaspaSignedTx: {
|
|
7620
7898
|
fields: {
|
|
7621
7899
|
signature: {
|
|
@@ -14063,6 +14341,13 @@ var nested$1 = {
|
|
|
14063
14341
|
MessageType_KaspaSignedTx: 11303,
|
|
14064
14342
|
MessageType_KaspaTxInputRequest: 11304,
|
|
14065
14343
|
MessageType_KaspaTxInputAck: 11305,
|
|
14344
|
+
MessageType_KaspaTxRequest: 11306,
|
|
14345
|
+
MessageType_KaspaTxAckInput: 11307,
|
|
14346
|
+
MessageType_KaspaTxAckOutput: 11308,
|
|
14347
|
+
MessageType_KaspaTxAckPayloadChunk: 11309,
|
|
14348
|
+
MessageType_KaspaTxAckPrevMeta: 11310,
|
|
14349
|
+
MessageType_KaspaTxAckPrevInput: 11311,
|
|
14350
|
+
MessageType_KaspaTxAckPrevOutput: 11312,
|
|
14066
14351
|
MessageType_NexaGetAddress: 11400,
|
|
14067
14352
|
MessageType_NexaAddress: 11401,
|
|
14068
14353
|
MessageType_NexaSignTx: 11402,
|
|
@@ -38313,9 +38598,10 @@ function getSigOpCountsHash(transaction, sighashType) {
|
|
|
38313
38598
|
return hashWriter.finalize();
|
|
38314
38599
|
}
|
|
38315
38600
|
function hashTxOut(hashWriter, output) {
|
|
38601
|
+
var _a;
|
|
38316
38602
|
hashWriter.writeUInt64LE(output.satoshis);
|
|
38317
38603
|
hashWriter.writeUInt16LE(0);
|
|
38318
|
-
hashWriter.writeVarBytes(Buffer.from(output.script, 'hex'));
|
|
38604
|
+
hashWriter.writeVarBytes(Buffer.from((_a = output.script) !== null && _a !== void 0 ? _a : '', 'hex'));
|
|
38319
38605
|
}
|
|
38320
38606
|
function getOutputsHash(transaction, inputNumber, sighashType) {
|
|
38321
38607
|
if (isSighashNone(sighashType)) {
|
|
@@ -38358,25 +38644,31 @@ function serialize(transaction, inputNumber) {
|
|
|
38358
38644
|
};
|
|
38359
38645
|
}
|
|
38360
38646
|
|
|
38647
|
+
const P2PK_SCRIPT = /^(20[0-9a-f]{64}ac|21[0-9a-f]{66}ab)$/i;
|
|
38648
|
+
const isStreamableScript = (script) => !script || P2PK_SCRIPT.test(script);
|
|
38361
38649
|
class KaspaSignTransaction extends BaseMethod {
|
|
38362
38650
|
constructor() {
|
|
38363
38651
|
super(...arguments);
|
|
38364
38652
|
this.hasBundle = false;
|
|
38653
|
+
this.supportsLegacy = false;
|
|
38654
|
+
this.supportsStreaming = false;
|
|
38365
38655
|
}
|
|
38366
38656
|
init() {
|
|
38367
|
-
var _a, _b, _c, _d, _e;
|
|
38657
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
38368
38658
|
this.checkDeviceId = true;
|
|
38369
38659
|
this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.NOT_INITIALIZE];
|
|
38370
38660
|
this.allowUsePreInitialize = true;
|
|
38371
38661
|
const payload = this.payload;
|
|
38372
38662
|
validateParams(payload, [
|
|
38373
38663
|
{ name: 'version', type: 'number' },
|
|
38374
|
-
{ name: 'sigHashType', type: 'number'
|
|
38664
|
+
{ name: 'sigHashType', type: 'number' },
|
|
38375
38665
|
{ name: 'inputs', type: 'array', required: true },
|
|
38376
38666
|
{ name: 'outputs', type: 'array', required: true },
|
|
38377
38667
|
{ name: 'lockTime', required: true },
|
|
38378
38668
|
{ name: 'sigOpCount', type: 'number' },
|
|
38379
38669
|
{ name: 'subNetworkID', type: 'string' },
|
|
38670
|
+
{ name: 'payload', type: 'hexString' },
|
|
38671
|
+
{ name: 'refTxs', type: 'array', allowEmpty: true },
|
|
38380
38672
|
{ name: 'useTweak', type: 'boolean' },
|
|
38381
38673
|
]);
|
|
38382
38674
|
const inputs = payload.inputs.map(input => {
|
|
@@ -38387,20 +38679,47 @@ class KaspaSignTransaction extends BaseMethod {
|
|
|
38387
38679
|
{ name: 'outputIndex', type: 'number', required: true },
|
|
38388
38680
|
{ name: 'sequenceNumber', required: true },
|
|
38389
38681
|
]);
|
|
38682
|
+
validateParams(input.output, [{ name: 'satoshis', required: true }]);
|
|
38390
38683
|
const addressN = validatePath(input.path, 3);
|
|
38391
38684
|
return Object.assign(Object.assign({}, input), { path: addressN, sigOpCount: (_a = input.sigOpCount) !== null && _a !== void 0 ? _a : 1 });
|
|
38392
38685
|
});
|
|
38686
|
+
(_a = payload.refTxs) === null || _a === void 0 ? void 0 : _a.forEach(refTx => {
|
|
38687
|
+
validateParams(refTx, [
|
|
38688
|
+
{ name: 'txId', type: 'string', required: true },
|
|
38689
|
+
{ name: 'version', type: 'number', required: true },
|
|
38690
|
+
{ name: 'inputs', type: 'array', required: true, allowEmpty: true },
|
|
38691
|
+
{ name: 'outputs', type: 'array', required: true, allowEmpty: true },
|
|
38692
|
+
{ name: 'payload', type: 'hexString' },
|
|
38693
|
+
]);
|
|
38694
|
+
});
|
|
38393
38695
|
const outputs = payload.outputs.map(output => {
|
|
38394
38696
|
var _a;
|
|
38395
38697
|
validateParams(output, [
|
|
38396
38698
|
{ name: 'satoshis', required: true },
|
|
38397
|
-
{ name: '
|
|
38699
|
+
{ name: 'address', type: 'string' },
|
|
38700
|
+
{ name: 'script', type: 'string' },
|
|
38398
38701
|
{ name: 'scriptVersion', type: 'number' },
|
|
38399
38702
|
]);
|
|
38400
|
-
return Object.assign(Object.assign({}, output), { scriptVersion: (_a = output.scriptVersion) !== null && _a !== void 0 ? _a : 0 });
|
|
38703
|
+
return Object.assign(Object.assign({}, output), { addressN: output.addressN ? validatePath(output.addressN, 3) : undefined, scriptVersion: (_a = output.scriptVersion) !== null && _a !== void 0 ? _a : 0 });
|
|
38401
38704
|
});
|
|
38402
38705
|
this.params = Object.assign(Object.assign({}, payload), { inputs,
|
|
38403
|
-
outputs, scheme: (
|
|
38706
|
+
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 });
|
|
38707
|
+
this.supportsLegacy =
|
|
38708
|
+
this.params.outputs.every(output => !!output.script) &&
|
|
38709
|
+
this.params.inputs.every(input => !!input.output.script) &&
|
|
38710
|
+
!this.params.payload &&
|
|
38711
|
+
Number((_h = this.params.gas) !== null && _h !== void 0 ? _h : 0) === 0 &&
|
|
38712
|
+
/^0*$/.test((_j = this.params.subNetworkID) !== null && _j !== void 0 ? _j : '');
|
|
38713
|
+
const isDefaultSigHashType = this.params.sigHashType === SignatureType.SIGHASH_ALL ||
|
|
38714
|
+
this.params.sigHashType === (SignatureType.SIGHASH_ALL | SignatureType.SIGHASH_FORKID);
|
|
38715
|
+
this.supportsStreaming =
|
|
38716
|
+
isDefaultSigHashType &&
|
|
38717
|
+
this.params.outputs.every(output => !!output.address || !!output.addressN) &&
|
|
38718
|
+
this.params.inputs.every(input => isStreamableScript(input.output.script)) &&
|
|
38719
|
+
this.params.outputs.every(output => isStreamableScript(output.script));
|
|
38720
|
+
if (!this.supportsLegacy && !this.supportsStreaming) {
|
|
38721
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'KaspaSignTransaction: outputs require either address/addressN (streaming protocol) or script (legacy protocol)');
|
|
38722
|
+
}
|
|
38404
38723
|
}
|
|
38405
38724
|
getVersionRange() {
|
|
38406
38725
|
return {
|
|
@@ -38449,23 +38768,188 @@ class KaspaSignTransaction extends BaseMethod {
|
|
|
38449
38768
|
return signature;
|
|
38450
38769
|
});
|
|
38451
38770
|
}
|
|
38771
|
+
ackPrevRequest(typedCall, request, requestIndex) {
|
|
38772
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
38773
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38774
|
+
const prevTxId = ((_a = request.prev_tx_id) !== null && _a !== void 0 ? _a : '').toLowerCase();
|
|
38775
|
+
const refTx = ((_b = this.params.refTxs) !== null && _b !== void 0 ? _b : []).find(tx => tx.txId.toLowerCase() === prevTxId);
|
|
38776
|
+
if (!refTx) {
|
|
38777
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, `KaspaSignTransaction: device requested previous transaction ${prevTxId || '(unknown)'}; provide it via refTxs`);
|
|
38778
|
+
}
|
|
38779
|
+
const requestType = request.request_type;
|
|
38780
|
+
if (requestType === 'KASPA_TX_PREV_META') {
|
|
38781
|
+
return typedCall('KaspaTxAckPrevMeta', 'KaspaTxRequest', {
|
|
38782
|
+
version: refTx.version,
|
|
38783
|
+
input_count: refTx.inputs.length,
|
|
38784
|
+
output_count: refTx.outputs.length,
|
|
38785
|
+
lock_time: ((_c = refTx.lockTime) !== null && _c !== void 0 ? _c : 0),
|
|
38786
|
+
subnetwork_id: (_d = refTx.subNetworkID) !== null && _d !== void 0 ? _d : utils.bytesToHex(zeroSubnetworkID()),
|
|
38787
|
+
gas: ((_e = refTx.gas) !== null && _e !== void 0 ? _e : 0),
|
|
38788
|
+
payload_length: ((_f = refTx.payload) !== null && _f !== void 0 ? _f : '').length / 2,
|
|
38789
|
+
});
|
|
38790
|
+
}
|
|
38791
|
+
if (requestType === 'KASPA_TX_INPUT') {
|
|
38792
|
+
const input = refTx.inputs[requestIndex];
|
|
38793
|
+
if (!input) {
|
|
38794
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `KaspaSignTransaction: device requested input ${requestIndex} of previous tx out of range`);
|
|
38795
|
+
}
|
|
38796
|
+
return typedCall('KaspaTxAckPrevInput', 'KaspaTxRequest', {
|
|
38797
|
+
previous_outpoint: {
|
|
38798
|
+
tx_id: input.prevTxId,
|
|
38799
|
+
index: input.outputIndex,
|
|
38800
|
+
},
|
|
38801
|
+
sequence: input.sequenceNumber,
|
|
38802
|
+
});
|
|
38803
|
+
}
|
|
38804
|
+
if (requestType === 'KASPA_TX_OUTPUT') {
|
|
38805
|
+
const output = refTx.outputs[requestIndex];
|
|
38806
|
+
if (!output) {
|
|
38807
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `KaspaSignTransaction: device requested output ${requestIndex} of previous tx out of range`);
|
|
38808
|
+
}
|
|
38809
|
+
return typedCall('KaspaTxAckPrevOutput', 'KaspaTxRequest', {
|
|
38810
|
+
amount: output.satoshis,
|
|
38811
|
+
script_version: (_g = output.scriptVersion) !== null && _g !== void 0 ? _g : 0,
|
|
38812
|
+
script_public_key: output.script,
|
|
38813
|
+
});
|
|
38814
|
+
}
|
|
38815
|
+
if (requestType === 'KASPA_TX_PAYLOAD') {
|
|
38816
|
+
const payloadHex = (_h = refTx.payload) !== null && _h !== void 0 ? _h : '';
|
|
38817
|
+
const payloadLength = payloadHex.length / 2;
|
|
38818
|
+
const length = (_j = request.request_payload_length) !== null && _j !== void 0 ? _j : payloadLength - requestIndex;
|
|
38819
|
+
return typedCall('KaspaTxAckPayloadChunk', 'KaspaTxRequest', {
|
|
38820
|
+
payload_chunk: payloadHex.substring(requestIndex * 2, (requestIndex + length) * 2),
|
|
38821
|
+
});
|
|
38822
|
+
}
|
|
38823
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `KaspaSignTransaction: unknown previous-tx request type ${requestType !== null && requestType !== void 0 ? requestType : 'undefined'}`);
|
|
38824
|
+
});
|
|
38825
|
+
}
|
|
38826
|
+
signTxStream(typedCall, firstResponse) {
|
|
38827
|
+
var _a, _b, _c, _d, _e;
|
|
38828
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38829
|
+
const { params } = this;
|
|
38830
|
+
const signatures = [];
|
|
38831
|
+
const inputScriptType = params.scheme === 'ecdsa' ? 'KASPA_SPEND_P2PK_ECDSA' : 'KASPA_SPEND_P2PK_SCHNORR';
|
|
38832
|
+
const saveSignature = (signature) => {
|
|
38833
|
+
if (signature && typeof signature.signature_index === 'number' && signature.signature) {
|
|
38834
|
+
signatures[signature.signature_index] = {
|
|
38835
|
+
index: signature.signature_index,
|
|
38836
|
+
signature: signature.signature,
|
|
38837
|
+
};
|
|
38838
|
+
}
|
|
38839
|
+
};
|
|
38840
|
+
const payloadHex = (_a = params.payload) !== null && _a !== void 0 ? _a : '';
|
|
38841
|
+
const payloadLength = payloadHex.length / 2;
|
|
38842
|
+
let response = firstResponse;
|
|
38843
|
+
while (true) {
|
|
38844
|
+
const request = response.message;
|
|
38845
|
+
saveSignature(request.signature);
|
|
38846
|
+
const requestType = request.request_type;
|
|
38847
|
+
if (requestType === 'KASPA_TX_FINISHED') {
|
|
38848
|
+
break;
|
|
38849
|
+
}
|
|
38850
|
+
const requestIndex = (_b = request.request_index) !== null && _b !== void 0 ? _b : 0;
|
|
38851
|
+
if (request.prev_tx_id || requestType === 'KASPA_TX_PREV_META') {
|
|
38852
|
+
response = yield this.ackPrevRequest(typedCall, request, requestIndex);
|
|
38853
|
+
}
|
|
38854
|
+
else if (requestType === 'KASPA_TX_INPUT') {
|
|
38855
|
+
const input = params.inputs[requestIndex];
|
|
38856
|
+
if (!input) {
|
|
38857
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `KaspaSignTransaction: device requested input ${requestIndex} out of range`);
|
|
38858
|
+
}
|
|
38859
|
+
response = yield typedCall('KaspaTxAckInput', 'KaspaTxRequest', {
|
|
38860
|
+
address_n: input.path,
|
|
38861
|
+
previous_outpoint: {
|
|
38862
|
+
tx_id: input.prevTxId,
|
|
38863
|
+
index: input.outputIndex,
|
|
38864
|
+
},
|
|
38865
|
+
amount: input.output.satoshis,
|
|
38866
|
+
sequence: input.sequenceNumber,
|
|
38867
|
+
sig_op_count: (_c = input.sigOpCount) !== null && _c !== void 0 ? _c : 1,
|
|
38868
|
+
script_type: inputScriptType,
|
|
38869
|
+
use_tweak: params.useTweak,
|
|
38870
|
+
});
|
|
38871
|
+
}
|
|
38872
|
+
else if (requestType === 'KASPA_TX_OUTPUT') {
|
|
38873
|
+
const output = params.outputs[requestIndex];
|
|
38874
|
+
if (!output) {
|
|
38875
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `KaspaSignTransaction: device requested output ${requestIndex} out of range`);
|
|
38876
|
+
}
|
|
38877
|
+
const isChange = !!output.addressN;
|
|
38878
|
+
response = yield typedCall('KaspaTxAckOutput', 'KaspaTxRequest', {
|
|
38879
|
+
script_type: isChange ? 'KASPA_PAYTOCHANGE' : 'KASPA_PAYTOADDRESS',
|
|
38880
|
+
amount: output.satoshis,
|
|
38881
|
+
address_n: (_d = output.addressN) !== null && _d !== void 0 ? _d : [],
|
|
38882
|
+
address: output.address,
|
|
38883
|
+
scheme: params.scheme,
|
|
38884
|
+
use_tweak: params.useTweak,
|
|
38885
|
+
});
|
|
38886
|
+
}
|
|
38887
|
+
else if (requestType === 'KASPA_TX_PAYLOAD') {
|
|
38888
|
+
const offset = requestIndex;
|
|
38889
|
+
const length = (_e = request.request_payload_length) !== null && _e !== void 0 ? _e : payloadLength - offset;
|
|
38890
|
+
const chunk = payloadHex.substring(offset * 2, (offset + length) * 2);
|
|
38891
|
+
response = yield typedCall('KaspaTxAckPayloadChunk', 'KaspaTxRequest', {
|
|
38892
|
+
payload_chunk: chunk,
|
|
38893
|
+
});
|
|
38894
|
+
}
|
|
38895
|
+
else {
|
|
38896
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `KaspaSignTransaction: unknown request type ${requestType !== null && requestType !== void 0 ? requestType : 'undefined'}`);
|
|
38897
|
+
}
|
|
38898
|
+
}
|
|
38899
|
+
const collected = signatures.filter(Boolean);
|
|
38900
|
+
if (collected.length !== params.inputs.length) {
|
|
38901
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `KaspaSignTransaction: expected ${params.inputs.length} signatures, received ${collected.length}`);
|
|
38902
|
+
}
|
|
38903
|
+
return collected;
|
|
38904
|
+
});
|
|
38905
|
+
}
|
|
38452
38906
|
run() {
|
|
38907
|
+
var _a, _b, _c;
|
|
38453
38908
|
return __awaiter(this, void 0, void 0, function* () {
|
|
38454
38909
|
this.checkFeatureVersionLimit(() => this.params.useTweak === false, () => this.getUseTweakVersionRange(), {
|
|
38455
38910
|
strictCheckDeviceSupport: true,
|
|
38456
38911
|
});
|
|
38457
|
-
const { raw: rawMessage } = serialize(this.params, 0);
|
|
38458
|
-
const input = this.params.inputs[0];
|
|
38459
38912
|
const { device, params } = this;
|
|
38460
|
-
const
|
|
38461
|
-
|
|
38462
|
-
|
|
38463
|
-
|
|
38464
|
-
|
|
38465
|
-
|
|
38466
|
-
|
|
38467
|
-
|
|
38468
|
-
|
|
38913
|
+
const payloadHex = (_a = params.payload) !== null && _a !== void 0 ? _a : '';
|
|
38914
|
+
const hasRefTxs = ((_c = (_b = params.refTxs) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0) > 0;
|
|
38915
|
+
const streamingReady = this.supportsStreaming && (hasRefTxs || !this.supportsLegacy);
|
|
38916
|
+
const streamingFields = streamingReady
|
|
38917
|
+
? {
|
|
38918
|
+
output_count: params.outputs.length,
|
|
38919
|
+
version: params.version,
|
|
38920
|
+
lock_time: params.lockTime,
|
|
38921
|
+
subnetwork_id: params.subNetworkID,
|
|
38922
|
+
gas: params.gas,
|
|
38923
|
+
payload_length: payloadHex.length / 2,
|
|
38924
|
+
}
|
|
38925
|
+
: {};
|
|
38926
|
+
const legacyFields = this.supportsLegacy
|
|
38927
|
+
? { raw_message: utils.bytesToHex(serialize(params, 0).raw) }
|
|
38928
|
+
: {};
|
|
38929
|
+
let response;
|
|
38930
|
+
try {
|
|
38931
|
+
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));
|
|
38932
|
+
}
|
|
38933
|
+
catch (error) {
|
|
38934
|
+
if (!this.supportsLegacy &&
|
|
38935
|
+
error instanceof hdShared.HardwareError &&
|
|
38936
|
+
error.errorCode === hdShared.HardwareErrorCode.RuntimeError &&
|
|
38937
|
+
String(error.message).includes('Failure_DataError')) {
|
|
38938
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodNeedUpgradeFirmware, 'KaspaSignTransaction: this transaction requires firmware with Kaspa streaming support');
|
|
38939
|
+
}
|
|
38940
|
+
throw error;
|
|
38941
|
+
}
|
|
38942
|
+
const typedCall = device.commands.typedCall.bind(device.commands);
|
|
38943
|
+
if (response.type === 'KaspaTxRequest') {
|
|
38944
|
+
if (!this.supportsStreaming) {
|
|
38945
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter, 'KaspaSignTransaction: device firmware uses the streaming protocol; every output requires address or addressN');
|
|
38946
|
+
}
|
|
38947
|
+
return this.signTxStream(typedCall, response);
|
|
38948
|
+
}
|
|
38949
|
+
if (!this.supportsLegacy) {
|
|
38950
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, 'KaspaSignTransaction: device chose the legacy protocol but the transaction is not legacy-signable');
|
|
38951
|
+
}
|
|
38952
|
+
return this.processTxRequest(typedCall, response, 0, []);
|
|
38469
38953
|
});
|
|
38470
38954
|
}
|
|
38471
38955
|
}
|
|
@@ -11,14 +11,36 @@ export type KaspaSignInputParams = {
|
|
|
11
11
|
sequenceNumber: number | string;
|
|
12
12
|
output: {
|
|
13
13
|
satoshis: number | string;
|
|
14
|
-
script
|
|
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
|
-
|
|
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;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kaspaSignTransaction.d.ts","sourceRoot":"","sources":["../../../src/types/api/kaspaSignTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AAC3E,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAExD,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,GAAG,MAAM,CAAC;IAChC,MAAM,EAAE;QACN,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"kaspaSignTransaction.d.ts","sourceRoot":"","sources":["../../../src/types/api/kaspaSignTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AAC3E,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAExD,MAAM,MAAM,cAAc,GAAG;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,GAAG,MAAM,CAAC;IAChC,MAAM,EAAE;QACN,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;QAE1B,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;IACF,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;IAG1B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAE7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAKF,MAAM,MAAM,wBAAwB,GAAG;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,GAAG,MAAM,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;IAC1B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,wBAAwB,EAAE,CAAC;IACnC,OAAO,EAAE,yBAAyB,EAAE,CAAC;IACrC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,oBAAoB,EAAE,CAAC;IAC/B,OAAO,EAAE,qBAAqB,EAAE,CAAC;IACjC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;IAC1B,WAAW,CAAC,EAAE,aAAa,CAAC;IAC5B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAGtB,MAAM,CAAC,EAAE,mBAAmB,EAAE,CAAC;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,oBAAoB,CAC1C,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,YAAY,GAAG,0BAA0B,GAChD,QAAQ,CAAC,cAAc,EAAE,CAAC,CAAC"}
|