@ledgerhq/hw-app-kaspa 1.3.0-nightly.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.
- package/.prettierrc +4 -0
- package/.turbo/turbo-build.log +4 -0
- package/CHANGELOG.md +7 -0
- package/LICENSE.txt +21 -0
- package/README.md +105 -0
- package/jest.config.ts +10 -0
- package/lib/Kaspa.d.ts +59 -0
- package/lib/Kaspa.d.ts.map +1 -0
- package/lib/Kaspa.js +185 -0
- package/lib/Kaspa.js.map +1 -0
- package/lib/base32.d.ts +11 -0
- package/lib/base32.d.ts.map +1 -0
- package/lib/base32.js +36 -0
- package/lib/base32.js.map +1 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +13 -0
- package/lib/index.js.map +1 -0
- package/lib/kaspa-util.d.ts +3 -0
- package/lib/kaspa-util.d.ts.map +1 -0
- package/lib/kaspa-util.js +102 -0
- package/lib/kaspa-util.js.map +1 -0
- package/lib/kaspaHwTransaction.d.ts +89 -0
- package/lib/kaspaHwTransaction.d.ts.map +1 -0
- package/lib/kaspaHwTransaction.js +157 -0
- package/lib/kaspaHwTransaction.js.map +1 -0
- package/lib-es/Kaspa.d.ts +59 -0
- package/lib-es/Kaspa.d.ts.map +1 -0
- package/lib-es/Kaspa.js +179 -0
- package/lib-es/Kaspa.js.map +1 -0
- package/lib-es/base32.d.ts +11 -0
- package/lib-es/base32.d.ts.map +1 -0
- package/lib-es/base32.js +33 -0
- package/lib-es/base32.js.map +1 -0
- package/lib-es/index.d.ts +4 -0
- package/lib-es/index.d.ts.map +1 -0
- package/lib-es/index.js +4 -0
- package/lib-es/index.js.map +1 -0
- package/lib-es/kaspa-util.d.ts +3 -0
- package/lib-es/kaspa-util.d.ts.map +1 -0
- package/lib-es/kaspa-util.js +95 -0
- package/lib-es/kaspa-util.js.map +1 -0
- package/lib-es/kaspaHwTransaction.d.ts +89 -0
- package/lib-es/kaspaHwTransaction.d.ts.map +1 -0
- package/lib-es/kaspaHwTransaction.js +150 -0
- package/lib-es/kaspaHwTransaction.js.map +1 -0
- package/package.json +43 -0
- package/src/Kaspa.ts +261 -0
- package/src/base32.ts +36 -0
- package/src/index.ts +9 -0
- package/src/kaspa-util.ts +107 -0
- package/src/kaspaHwTransaction.ts +244 -0
- package/tests/kaspa.test.ts +724 -0
- package/tsconfig.json +25 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
type TransactionApiJSON = {
|
|
3
|
+
transaction: {
|
|
4
|
+
version: number;
|
|
5
|
+
inputs: TransactionInputApiJSON[];
|
|
6
|
+
outputs: TransactionOutputApiJSON[];
|
|
7
|
+
lockTime: number;
|
|
8
|
+
subnetworkId: string;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export declare class KaspaHwTransaction {
|
|
12
|
+
inputs: TransactionInput[];
|
|
13
|
+
outputs: TransactionOutput[];
|
|
14
|
+
version: number;
|
|
15
|
+
changeAddressType: number;
|
|
16
|
+
changeAddressIndex: number;
|
|
17
|
+
account: number;
|
|
18
|
+
constructor(txData: {
|
|
19
|
+
inputs: TransactionInput[];
|
|
20
|
+
outputs: TransactionOutput[];
|
|
21
|
+
version: number;
|
|
22
|
+
changeAddressType?: number;
|
|
23
|
+
changeAddressIndex?: number;
|
|
24
|
+
account?: number;
|
|
25
|
+
});
|
|
26
|
+
serialize(): Buffer;
|
|
27
|
+
/**
|
|
28
|
+
* Convert this transaction to a JSON object that api.kaspa.org will accept
|
|
29
|
+
*/
|
|
30
|
+
toApiJSON(): TransactionApiJSON;
|
|
31
|
+
}
|
|
32
|
+
type TransactionInputApiJSON = {
|
|
33
|
+
previousOutpoint: {
|
|
34
|
+
transactionId: string;
|
|
35
|
+
index: number;
|
|
36
|
+
};
|
|
37
|
+
signatureScript: string | null;
|
|
38
|
+
sequence: number;
|
|
39
|
+
sigOpCount: number;
|
|
40
|
+
};
|
|
41
|
+
export declare class TransactionInput {
|
|
42
|
+
signature?: string | null;
|
|
43
|
+
sighash?: string | null;
|
|
44
|
+
value: number;
|
|
45
|
+
prevTxId: string;
|
|
46
|
+
outpointIndex: number;
|
|
47
|
+
addressType: number;
|
|
48
|
+
addressIndex: number;
|
|
49
|
+
constructor(inputData: {
|
|
50
|
+
value: number;
|
|
51
|
+
prevTxId: string;
|
|
52
|
+
outpointIndex: number;
|
|
53
|
+
addressType: number;
|
|
54
|
+
addressIndex: number;
|
|
55
|
+
});
|
|
56
|
+
serialize(): Buffer;
|
|
57
|
+
/**
|
|
58
|
+
*
|
|
59
|
+
* @param {string} signature
|
|
60
|
+
*/
|
|
61
|
+
setSignature(signature: string): void;
|
|
62
|
+
setSighash(sighash: string): void;
|
|
63
|
+
toApiJSON(): TransactionInputApiJSON;
|
|
64
|
+
}
|
|
65
|
+
type TransactionOutputApiJSON = {
|
|
66
|
+
amount: number;
|
|
67
|
+
scriptPublicKey: {
|
|
68
|
+
version: number;
|
|
69
|
+
scriptPublicKey: string;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
export declare class TransactionOutput {
|
|
73
|
+
value: number;
|
|
74
|
+
scriptPublicKey: string;
|
|
75
|
+
constructor(outputData: {
|
|
76
|
+
value: number;
|
|
77
|
+
scriptPublicKey: string;
|
|
78
|
+
});
|
|
79
|
+
serialize(): Buffer;
|
|
80
|
+
toApiJSON(): TransactionOutputApiJSON;
|
|
81
|
+
}
|
|
82
|
+
export declare function toBigEndianHex(numberToConvert: number): string;
|
|
83
|
+
declare const _default: {
|
|
84
|
+
Transaction: typeof KaspaHwTransaction;
|
|
85
|
+
TransactionInput: typeof TransactionInput;
|
|
86
|
+
TransactionOutput: typeof TransactionOutput;
|
|
87
|
+
};
|
|
88
|
+
export default _default;
|
|
89
|
+
//# sourceMappingURL=kaspaHwTransaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kaspaHwTransaction.d.ts","sourceRoot":"","sources":["../src/kasp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ACjB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;gBAET,SAAS,EAAE;QACrB,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,MAAM,CAAC;QACjB,aAAa,EAAE,MAAM,CAAC;QACtB,WAAW,EAAE,MAAM,CAAC;QACpB,YAAY,EAAE,MAAM,CAAC;KACtB;IAUD,SAAS,IAAI,MAAM;IAqBnB;;;OAGG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAIrC,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAIjC,SAAS,IAAI,uBAAuB;CAWrC;AAED,KAAK,wBAAwB,GAAG;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE;QACf,OAAO,EAAE,MAAM,CAAC;QAChB,eAAe,EAAE,MAAM,CAAC;KACzB,CAAC;CACH,CAAC;AAEF,qBAAa,iBAAiB;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,eAAe,EAAE,MAAM,CAAC;gBAEZ,UAAU,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,eAAe,EAAE,MAAM,CAAA;KAAE;IAgBlE,SAAS,IAAI,MAAM;IAKnB,SAAS,IAAI,wBAAwB;CAStC;AAED,wBAAgB,cAAc,CAAC,eAAe,EAAE,MAAM,UAMrD;;;;;;AAED,wBAIE"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toBigEndianHex = exports.TransactionOutput = exports.TransactionInput = exports.KaspaHwTransaction = void 0;
|
|
4
|
+
class KaspaHwTransaction {
|
|
5
|
+
constructor(txData) {
|
|
6
|
+
var _a, _b, _c;
|
|
7
|
+
/**
|
|
8
|
+
* @type {TransactionInput[]}
|
|
9
|
+
*/
|
|
10
|
+
this.inputs = txData.inputs;
|
|
11
|
+
/**
|
|
12
|
+
* @type {TransactionOutput[]}
|
|
13
|
+
*/
|
|
14
|
+
this.outputs = txData.outputs;
|
|
15
|
+
/**
|
|
16
|
+
* @type {int}
|
|
17
|
+
*/
|
|
18
|
+
this.version = txData.version;
|
|
19
|
+
this.changeAddressType = (_a = txData.changeAddressType) !== null && _a !== void 0 ? _a : 0;
|
|
20
|
+
this.changeAddressIndex = (_b = txData.changeAddressIndex) !== null && _b !== void 0 ? _b : 0;
|
|
21
|
+
this.account = (_c = txData.account) !== null && _c !== void 0 ? _c : 0x80000000;
|
|
22
|
+
if (!(this.changeAddressType === 0 || this.changeAddressType === 1)) {
|
|
23
|
+
throw new Error("changeAddressType must be 0 or 1 if set");
|
|
24
|
+
}
|
|
25
|
+
if (this.account < 0x80000000 || this.account > 0xffffffff) {
|
|
26
|
+
throw new Error("account must be between 0x80000000 and 0xFFFFFFFF");
|
|
27
|
+
}
|
|
28
|
+
if (this.changeAddressIndex < 0x00000000 ||
|
|
29
|
+
this.changeAddressIndex > 0xffffffff) {
|
|
30
|
+
throw new Error(`changeAddressIndex must be between 0x00000000 and 0xFFFFFFFF`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
serialize() {
|
|
34
|
+
const versionBuf = Buffer.alloc(2);
|
|
35
|
+
versionBuf.writeUInt16BE(this.version);
|
|
36
|
+
const outputLenBuf = Buffer.alloc(1);
|
|
37
|
+
outputLenBuf.writeUInt8(this.outputs.length);
|
|
38
|
+
const inputLenBuf = Buffer.alloc(1);
|
|
39
|
+
inputLenBuf.writeUInt8(this.inputs.length);
|
|
40
|
+
const changeAddressTypeBuf = Buffer.alloc(1);
|
|
41
|
+
changeAddressTypeBuf.writeUInt8(this.changeAddressType);
|
|
42
|
+
const changeAddressIndexBuf = Buffer.alloc(4);
|
|
43
|
+
changeAddressIndexBuf.writeUInt32BE(this.changeAddressIndex);
|
|
44
|
+
const accountBuf = Buffer.alloc(4);
|
|
45
|
+
accountBuf.writeUInt32BE(this.account);
|
|
46
|
+
return Buffer.concat([
|
|
47
|
+
versionBuf,
|
|
48
|
+
outputLenBuf,
|
|
49
|
+
inputLenBuf,
|
|
50
|
+
changeAddressTypeBuf,
|
|
51
|
+
changeAddressIndexBuf,
|
|
52
|
+
accountBuf,
|
|
53
|
+
]);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Convert this transaction to a JSON object that api.kaspa.org will accept
|
|
57
|
+
*/
|
|
58
|
+
toApiJSON() {
|
|
59
|
+
return {
|
|
60
|
+
transaction: {
|
|
61
|
+
version: this.version,
|
|
62
|
+
inputs: this.inputs.map((i) => i.toApiJSON()),
|
|
63
|
+
outputs: this.outputs.map((o) => o.toApiJSON()),
|
|
64
|
+
lockTime: 0,
|
|
65
|
+
subnetworkId: "0000000000000000000000000000000000000000",
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
exports.KaspaHwTransaction = KaspaHwTransaction;
|
|
71
|
+
class TransactionInput {
|
|
72
|
+
constructor(inputData) {
|
|
73
|
+
this.value = inputData.value;
|
|
74
|
+
this.prevTxId = inputData.prevTxId;
|
|
75
|
+
this.outpointIndex = inputData.outpointIndex;
|
|
76
|
+
this.addressType = inputData.addressType;
|
|
77
|
+
this.addressIndex = inputData.addressIndex;
|
|
78
|
+
this.signature = null;
|
|
79
|
+
this.sighash = null;
|
|
80
|
+
}
|
|
81
|
+
serialize() {
|
|
82
|
+
const valueBuf = Buffer.from(toBigEndianHex(this.value), "hex");
|
|
83
|
+
const addressTypeBuf = Buffer.alloc(1);
|
|
84
|
+
addressTypeBuf.writeUInt8(this.addressType);
|
|
85
|
+
const addressIndexBuf = Buffer.alloc(4);
|
|
86
|
+
addressIndexBuf.writeUInt32BE(this.addressIndex);
|
|
87
|
+
const outpointIndexBuf = Buffer.alloc(1);
|
|
88
|
+
outpointIndexBuf.writeUInt8(this.outpointIndex);
|
|
89
|
+
return Buffer.concat([
|
|
90
|
+
valueBuf,
|
|
91
|
+
Buffer.from(this.prevTxId, "hex"),
|
|
92
|
+
addressTypeBuf,
|
|
93
|
+
addressIndexBuf,
|
|
94
|
+
outpointIndexBuf,
|
|
95
|
+
]);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
*
|
|
99
|
+
* @param {string} signature
|
|
100
|
+
*/
|
|
101
|
+
setSignature(signature) {
|
|
102
|
+
this.signature = signature;
|
|
103
|
+
}
|
|
104
|
+
setSighash(sighash) {
|
|
105
|
+
this.sighash = sighash;
|
|
106
|
+
}
|
|
107
|
+
toApiJSON() {
|
|
108
|
+
return {
|
|
109
|
+
previousOutpoint: {
|
|
110
|
+
transactionId: this.prevTxId,
|
|
111
|
+
index: this.outpointIndex,
|
|
112
|
+
},
|
|
113
|
+
signatureScript: this.signature ? `41${this.signature}01` : null,
|
|
114
|
+
sequence: 0,
|
|
115
|
+
sigOpCount: 1,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
exports.TransactionInput = TransactionInput;
|
|
120
|
+
class TransactionOutput {
|
|
121
|
+
constructor(outputData) {
|
|
122
|
+
if (!outputData.value ||
|
|
123
|
+
outputData.value < 0 ||
|
|
124
|
+
outputData.value > Number.MAX_SAFE_INTEGER) {
|
|
125
|
+
throw new Error(`value must be set to a value greater than 0 and less than ${Number.MAX_SAFE_INTEGER.toString()}`);
|
|
126
|
+
}
|
|
127
|
+
this.value = outputData.value;
|
|
128
|
+
// Only then do we care about the script public key
|
|
129
|
+
this.scriptPublicKey = outputData.scriptPublicKey;
|
|
130
|
+
}
|
|
131
|
+
serialize() {
|
|
132
|
+
const valueBuf = Buffer.from(toBigEndianHex(this.value), "hex");
|
|
133
|
+
return Buffer.concat([valueBuf, Buffer.from(this.scriptPublicKey, "hex")]);
|
|
134
|
+
}
|
|
135
|
+
toApiJSON() {
|
|
136
|
+
return {
|
|
137
|
+
amount: this.value,
|
|
138
|
+
scriptPublicKey: {
|
|
139
|
+
version: 0,
|
|
140
|
+
scriptPublicKey: this.scriptPublicKey,
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
exports.TransactionOutput = TransactionOutput;
|
|
146
|
+
function toBigEndianHex(numberToConvert) {
|
|
147
|
+
let baseStr = "0000000000000000";
|
|
148
|
+
baseStr += numberToConvert.toString(16);
|
|
149
|
+
return baseStr.substring(baseStr.length - 16, baseStr.length);
|
|
150
|
+
}
|
|
151
|
+
exports.toBigEndianHex = toBigEndianHex;
|
|
152
|
+
exports.default = {
|
|
153
|
+
Transaction: KaspaHwTransaction,
|
|
154
|
+
TransactionInput,
|
|
155
|
+
TransactionOutput,
|
|
156
|
+
};
|
|
157
|
+
//# sourceMappingURL=kaspaHwTransaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kaspaHwTransaction.js","sourceRoot":"","sources":["../src/kaspaHwTransaction.ts"],"names":[],"mappings":";;;AAUA,MAAa,kBAAkB;IAQ7B,YAAY,MAOX;;QACC;;WAEG;QACH,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QAC5B;;WAEG;QACH,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC9B;;WAEG;QACH,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAE9B,IAAI,CAAC,iBAAiB,GAAG,MAAA,MAAM,CAAC,iBAAiB,mCAAI,CAAC,CAAC;QACvD,IAAI,CAAC,kBAAkB,GAAG,MAAA,MAAM,CAAC,kBAAkB,mCAAI,CAAC,CAAC;QACzD,IAAI,CAAC,OAAO,GAAG,MAAA,MAAM,CAAC,OAAO,mCAAI,UAAU,CAAC;QAE5C,IAAI,CAAC,CAAC,IAAI,CAAC,iBAAiB,KAAK,CAAC,IAAI,IAAI,CAAC,iBAAiB,KAAK,CAAC,CAAC,EAAE,CAAC;YACpE,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;QAC7D,CAAC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CAAC;IAED,SAAS;QACP,MAAM,QAAQ,GAAW,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC;QACxE,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;IAC7E,CAAC;IAED,SAAS;QACP,OAAO;YACL,MAAM,EAAE,IAAI,CAAC,KAAK;YAClB,eAAe,EAAE;gBACf,OAAO,EAAE,CAAC;gBACV,eAAe,EAAE,IAAI,CAAC,eAAe;aACtC;SACF,CAAC;IACJ,CAAC;CACF;AAlCD,8CAkCC;AAED,SAAgB,cAAc,CAAC,eAAuB;IACpD,IAAI,OAAO,GAAG,kBAAkB,CAAC;IAEjC,OAAO,IAAI,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IAExC,OAAO,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,GAAG,EAAE,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;AAChE,CAAC;AAND,wCAMC;AAED,kBAAe;IACb,WAAW,EAAE,kBAAkB;IAC/B,gBAAgB;IAChB,iBAAiB;CAClB,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import Transport from "@ledgerhq/hw-transport";
|
|
3
|
+
import { KaspaHwTransaction } from "./kaspaHwTransaction";
|
|
4
|
+
export default class Kaspa {
|
|
5
|
+
transport: Transport;
|
|
6
|
+
constructor(transport: Transport);
|
|
7
|
+
/**
|
|
8
|
+
* Get Kaspa address (public key) for a BIP32 path.
|
|
9
|
+
*
|
|
10
|
+
* @param {string} path a BIP32 path
|
|
11
|
+
* @param {boolean} display flag to show display
|
|
12
|
+
* @return an object with the address field
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* kaspa.getAddress("44'/111111'/0'").then(r => r.address)
|
|
16
|
+
*/
|
|
17
|
+
getAddress(path: string, display?: boolean): Promise<{
|
|
18
|
+
publicKey: string;
|
|
19
|
+
address: string;
|
|
20
|
+
}>;
|
|
21
|
+
/**
|
|
22
|
+
* Sign a Kaspa transaction. Applies the signatures into the input objects
|
|
23
|
+
*
|
|
24
|
+
* @param {KaspaHwTransaction} transaction - the Transaction object
|
|
25
|
+
*
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* kaspa.signTransaction(transaction)
|
|
29
|
+
*/
|
|
30
|
+
signTransaction(transaction: KaspaHwTransaction): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Sign personal message on the device
|
|
33
|
+
* @param {String} message - the personal message string to sign. Max 120 len for Nano S, 200 len for others
|
|
34
|
+
* @param {0|1} addressType
|
|
35
|
+
* @param {number} addressIndex
|
|
36
|
+
*
|
|
37
|
+
* @returns {Buffer} application config object
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* kaspa.signMessage(message).then(r => r.version)
|
|
41
|
+
*/
|
|
42
|
+
signMessage(message: string, addressType?: 0 | 1, addressIndex?: number, account?: number): Promise<{
|
|
43
|
+
signature: string;
|
|
44
|
+
messageHash: string;
|
|
45
|
+
}>;
|
|
46
|
+
/**
|
|
47
|
+
* Get application configuration.
|
|
48
|
+
*
|
|
49
|
+
* @returns {Buffer} application config object
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* kaspa.getVersion().then(r => r.version)
|
|
53
|
+
*/
|
|
54
|
+
getVersion(): Promise<{
|
|
55
|
+
version: string;
|
|
56
|
+
}>;
|
|
57
|
+
sendToDevice(instruction: any, p1: any, payload?: Buffer, p2?: number): Promise<Buffer>;
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=Kaspa.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Kaspa.d.ts","sourceRoot":"","sources":["../src/Kaspa.ts"],"names":[],"mappings":";AAAA,OAAO,SAAS,MAAM,wBAAwB,CAAC;AAI/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAwC1D,MAAM,CAAC,OAAO,OAAO,KAAK;IACxB,SAAS,EAAE,SAAS,CAAC;gBAET,SAAS,EAAE,SAAS;IAShC;;;;;;;;;OASG;IACG,UAAU,CACd,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,OAAe,GACvB,OAAO,CAAC;QACT,SAAS,EAAE,MAAM,CAAC;QAClB,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IAiBF;;;;;;;;OAQG;IACG,eAAe,CAAC,WAAW,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IA8DrE;;;;;;;;;;OAUG;IACG,WAAW,CACf,OAAO,EAAE,MAAM,EACf,WAAW,CAAC,EAAE,CAAC,GAAG,CAAC,EACnB,YAAY,CAAC,EAAE,MAAM,EACrB,OAAO,CAAC,EAAE,MAAM;;;;IAsDlB;;;;;;;OAOG;IACG,UAAU;;;IASV,YAAY,CAAC,WAAW,KAAA,EAAE,EAAE,KAAA,EAAE,OAAO,SAAkB,EAAE,EAAE,SAAU;CAc5E"}
|
package/lib-es/Kaspa.js
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { StatusCodes } from "@ledgerhq/errors";
|
|
11
|
+
import { publicKeyToAddress } from "./kaspa-util";
|
|
12
|
+
import BIP32Path from "bip32-path";
|
|
13
|
+
// Get Address
|
|
14
|
+
const P1_NON_CONFIRM = 0x00;
|
|
15
|
+
const P1_CONFIRM = 0x01;
|
|
16
|
+
// Sign Transaction
|
|
17
|
+
const P1_HEADER = 0x00;
|
|
18
|
+
const P1_OUTPUTS = 0x01;
|
|
19
|
+
const P1_INPUTS = 0x02;
|
|
20
|
+
const P1_NEXT_SIGNATURE = 0x03;
|
|
21
|
+
const P2_LAST = 0x00;
|
|
22
|
+
const P2_MORE = 0x80;
|
|
23
|
+
const LEDGER_CLA = 0xe0;
|
|
24
|
+
const INS = {
|
|
25
|
+
GET_VERSION: 0x04,
|
|
26
|
+
GET_ADDRESS: 0x05,
|
|
27
|
+
SIGN_TX: 0x06,
|
|
28
|
+
SIGN_MESSAGE: 0x07,
|
|
29
|
+
};
|
|
30
|
+
function pathToBuffer(originalPath) {
|
|
31
|
+
const pathNums = BIP32Path.fromString(originalPath).toPathArray();
|
|
32
|
+
return serializePath(pathNums);
|
|
33
|
+
}
|
|
34
|
+
function serializePath(path) {
|
|
35
|
+
const buf = Buffer.alloc(1 + path.length * 4);
|
|
36
|
+
buf.writeUInt8(path.length, 0);
|
|
37
|
+
for (const [i, num] of path.entries()) {
|
|
38
|
+
buf.writeUInt32BE(num, 1 + i * 4);
|
|
39
|
+
}
|
|
40
|
+
return buf;
|
|
41
|
+
}
|
|
42
|
+
export default class Kaspa {
|
|
43
|
+
constructor(transport) {
|
|
44
|
+
this.transport = transport;
|
|
45
|
+
this.transport.decorateAppAPIMethods(this, ["getVersion", "getAddress", "signTransaction", "signMessage"], "kaspa");
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Get Kaspa address (public key) for a BIP32 path.
|
|
49
|
+
*
|
|
50
|
+
* @param {string} path a BIP32 path
|
|
51
|
+
* @param {boolean} display flag to show display
|
|
52
|
+
* @return an object with the address field
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* kaspa.getAddress("44'/111111'/0'").then(r => r.address)
|
|
56
|
+
*/
|
|
57
|
+
getAddress(path_1) {
|
|
58
|
+
return __awaiter(this, arguments, void 0, function* (path, display = false) {
|
|
59
|
+
const pathBuffer = pathToBuffer(path);
|
|
60
|
+
const p1 = display ? P1_CONFIRM : P1_NON_CONFIRM;
|
|
61
|
+
const publicKeyBuffer = yield this.sendToDevice(INS.GET_ADDRESS, p1, pathBuffer);
|
|
62
|
+
return {
|
|
63
|
+
publicKey: publicKeyBuffer.toString("hex"),
|
|
64
|
+
address: publicKeyToAddress(publicKeyBuffer.subarray(2, 34)),
|
|
65
|
+
};
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Sign a Kaspa transaction. Applies the signatures into the input objects
|
|
70
|
+
*
|
|
71
|
+
* @param {KaspaHwTransaction} transaction - the Transaction object
|
|
72
|
+
*
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* kaspa.signTransaction(transaction)
|
|
76
|
+
*/
|
|
77
|
+
signTransaction(transaction) {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
const header = transaction.serialize();
|
|
80
|
+
yield this.sendToDevice(INS.SIGN_TX, P1_HEADER, header, P2_MORE);
|
|
81
|
+
for (const output of transaction.outputs) {
|
|
82
|
+
yield this.sendToDevice(INS.SIGN_TX, P1_OUTPUTS, output.serialize(), P2_MORE);
|
|
83
|
+
}
|
|
84
|
+
let signatureBuffer = null;
|
|
85
|
+
for (let i = 0; i < transaction.inputs.length; i++) {
|
|
86
|
+
const p2 = i >= transaction.inputs.length - 1 ? P2_LAST : P2_MORE;
|
|
87
|
+
const input = transaction.inputs[i];
|
|
88
|
+
signatureBuffer = yield this.sendToDevice(INS.SIGN_TX, P1_INPUTS, input.serialize(), p2);
|
|
89
|
+
}
|
|
90
|
+
while (signatureBuffer) {
|
|
91
|
+
const [hasMore, inputIndex, sigLen, ...signatureAndSighash] = signatureBuffer;
|
|
92
|
+
const sigBuf = signatureAndSighash.slice(0, sigLen);
|
|
93
|
+
const sighashLen = signatureAndSighash[64];
|
|
94
|
+
const sighashBuf = signatureAndSighash.slice(65, 65 + sighashLen);
|
|
95
|
+
if (sigLen != 64) {
|
|
96
|
+
throw new Error(`Expected signature length is 64. Received ${sigLen} for input ${inputIndex}`);
|
|
97
|
+
}
|
|
98
|
+
if (sighashLen != 32) {
|
|
99
|
+
throw new Error(`Expected sighash length is 32. Received ${sighashLen} for input ${inputIndex}`);
|
|
100
|
+
}
|
|
101
|
+
transaction.inputs[inputIndex].setSignature(Buffer.from(sigBuf).toString("hex"));
|
|
102
|
+
transaction.inputs[inputIndex].setSighash(Buffer.from(sighashBuf).toString("hex"));
|
|
103
|
+
// Keep going as long as hasMore is true-ish
|
|
104
|
+
if (!hasMore) {
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
signatureBuffer = yield this.sendToDevice(INS.SIGN_TX, P1_NEXT_SIGNATURE);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Sign personal message on the device
|
|
113
|
+
* @param {String} message - the personal message string to sign. Max 120 len for Nano S, 200 len for others
|
|
114
|
+
* @param {0|1} addressType
|
|
115
|
+
* @param {number} addressIndex
|
|
116
|
+
*
|
|
117
|
+
* @returns {Buffer} application config object
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* kaspa.signMessage(message).then(r => r.version)
|
|
121
|
+
*/
|
|
122
|
+
signMessage(message, addressType, addressIndex, account) {
|
|
123
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
124
|
+
account = account !== null && account !== void 0 ? account : 0x80000000;
|
|
125
|
+
addressIndex = addressIndex !== null && addressIndex !== void 0 ? addressIndex : 0;
|
|
126
|
+
addressType = addressType !== null && addressType !== void 0 ? addressType : 0;
|
|
127
|
+
if (account < 0x80000000 || account > 0xffffffff) {
|
|
128
|
+
throw new Error("Account must be between 0x80000000 and 0xFFFFFFFF");
|
|
129
|
+
}
|
|
130
|
+
if (addressIndex < 0 || addressIndex > 0xffffffff) {
|
|
131
|
+
throw new Error("Address index must be an integer in range [0, 0xFFFFFFFF]");
|
|
132
|
+
}
|
|
133
|
+
const addressTypeBuf = Buffer.alloc(1);
|
|
134
|
+
addressTypeBuf.writeUInt8(addressType || 0);
|
|
135
|
+
const addressIndexBuf = Buffer.alloc(4);
|
|
136
|
+
addressIndexBuf.writeUInt32BE(addressIndex || 0);
|
|
137
|
+
const accountBuf = Buffer.alloc(4);
|
|
138
|
+
accountBuf.writeUInt32BE(account);
|
|
139
|
+
const messageBuffer = Buffer.from(message);
|
|
140
|
+
const messageLenBuf = Buffer.alloc(1);
|
|
141
|
+
messageLenBuf.writeUInt8(messageBuffer.length);
|
|
142
|
+
const payload = Buffer.concat([
|
|
143
|
+
addressTypeBuf,
|
|
144
|
+
addressIndexBuf,
|
|
145
|
+
accountBuf,
|
|
146
|
+
messageLenBuf,
|
|
147
|
+
messageBuffer,
|
|
148
|
+
]);
|
|
149
|
+
const signatureBuffer = yield this.sendToDevice(INS.SIGN_MESSAGE, P1_NON_CONFIRM, payload);
|
|
150
|
+
const [sigLen, ...signatureAndMessageHash] = signatureBuffer;
|
|
151
|
+
const signature = Buffer.from(signatureAndMessageHash.slice(0, sigLen)).toString("hex");
|
|
152
|
+
const messageHashLen = signatureAndMessageHash[64];
|
|
153
|
+
const messageHash = Buffer.from(signatureAndMessageHash.slice(65, 65 + messageHashLen)).toString("hex");
|
|
154
|
+
return { signature, messageHash };
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Get application configuration.
|
|
159
|
+
*
|
|
160
|
+
* @returns {Buffer} application config object
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* kaspa.getVersion().then(r => r.version)
|
|
164
|
+
*/
|
|
165
|
+
getVersion() {
|
|
166
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
167
|
+
const [major, minor, patch] = yield this.sendToDevice(INS.GET_VERSION, P1_NON_CONFIRM);
|
|
168
|
+
return { version: `${major}.${minor}.${patch}` };
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
sendToDevice(instruction_1, p1_1) {
|
|
172
|
+
return __awaiter(this, arguments, void 0, function* (instruction, p1, payload = Buffer.alloc(0), p2 = P2_LAST) {
|
|
173
|
+
const acceptStatusList = [StatusCodes.OK];
|
|
174
|
+
const reply = yield this.transport.send(LEDGER_CLA, instruction, p1, p2, payload, acceptStatusList);
|
|
175
|
+
return reply.subarray(0, reply.length - 2);
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=Kaspa.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Kaspa.js","sourceRoot":"","sources":["../src/Kaspa.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAGlD,OAAO,SAAS,MAAM,YAAY,CAAC;AAEnC,cAAc;AACd,MAAM,cAAc,GAAG,IAAI,CAAC;AAC5B,MAAM,UAAU,GAAG,IAAI,CAAC;AAExB,mBAAmB;AACnB,MAAM,SAAS,GAAG,IAAI,CAAC;AACvB,MAAM,UAAU,GAAG,IAAI,CAAC;AACxB,MAAM,SAAS,GAAG,IAAI,CAAC;AACvB,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAE/B,MAAM,OAAO,GAAG,IAAI,CAAC;AACrB,MAAM,OAAO,GAAG,IAAI,CAAC;AAErB,MAAM,UAAU,GAAG,IAAI,CAAC;AAExB,MAAM,GAAG,GAAG;IACV,WAAW,EAAE,IAAI;IACjB,WAAW,EAAE,IAAI;IACjB,OAAO,EAAE,IAAI;IACb,YAAY,EAAE,IAAI;CACnB,CAAC;AAEF,SAAS,YAAY,CAAC,YAAY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W,GAAG,MAAM,CAAC,IAAI,CAC7B,uBAAuB,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,GAAG,cAAc,CAAC,CACvD,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YAElB,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC;QACpC,CAAC;KAAA;IAED;;;;;;;OAOG;IACG,UAAU;;YACd,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,GAAG,MAAM,IAAI,CAAC,YAAY,CACnD,GAAG,CAAC,WAAW,EACf,cAAc,CACf,CAAC;YAEF,OAAO,EAAE,OAAO,EAAE,GAAG,KAAK,IAAI,KAAK,IAAI,KAAK,EAAE,EAAE,CAAC;QACnD,CAAC;KAAA;IAEK,YAAY;6DAAC,WAAW,EAAE,EAAE,EAAE,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,GAAG,OAAO;YACzE,MAAM,gBAAgB,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;YAE1C,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CACrC,UAAU,EACV,WAAW,EACX,EAAE,EACF,EAAE,EACF,OAAO,EACP,gBAAgB,CACjB,CAAC;YAEF,OAAO,KAAK,CAAC,QAAQ,CAAC,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAC7C,CAAC;KAAA;CACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/***
|
|
2
|
+
* Encodes the given array of 5-bit integers as a base32-encoded string.
|
|
3
|
+
*
|
|
4
|
+
* @param {Array} data Array of integers between 0 and 31 inclusive.
|
|
5
|
+
*/
|
|
6
|
+
export declare function encode(data: Array<number>): string;
|
|
7
|
+
declare const base32: {
|
|
8
|
+
encode: typeof encode;
|
|
9
|
+
};
|
|
10
|
+
export default base32;
|
|
11
|
+
//# sourceMappingURL=base32.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base32.d.ts","sourceRoot":"","sources":["../src/base32.ts"],"names":[],"mappings":"AAcA;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,UAUzC;AAED,QAAA,MAAM,MAAM;;CAEX,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
package/lib-es/base32.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/***
|
|
3
|
+
* https://github.com/bitcoincashjs/cashaddr
|
|
4
|
+
* Copyright (c) 2018 Matias Alejo Garcia
|
|
5
|
+
* Copyright (c) 2017 Emilio Almansi
|
|
6
|
+
* Distributed under the MIT software license, see the accompanying
|
|
7
|
+
* file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
|
8
|
+
*/
|
|
9
|
+
/***
|
|
10
|
+
* Charset containing the 32 symbols used in the base32 encoding.
|
|
11
|
+
*/
|
|
12
|
+
const CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l";
|
|
13
|
+
/***
|
|
14
|
+
* Encodes the given array of 5-bit integers as a base32-encoded string.
|
|
15
|
+
*
|
|
16
|
+
* @param {Array} data Array of integers between 0 and 31 inclusive.
|
|
17
|
+
*/
|
|
18
|
+
export function encode(data) {
|
|
19
|
+
let base32 = "";
|
|
20
|
+
for (let i = 0; i < data.length; i++) {
|
|
21
|
+
const value = data[i];
|
|
22
|
+
if (!(0 <= value && value < 32)) {
|
|
23
|
+
throw new Error("value " + value);
|
|
24
|
+
}
|
|
25
|
+
base32 += CHARSET[value];
|
|
26
|
+
}
|
|
27
|
+
return base32;
|
|
28
|
+
}
|
|
29
|
+
const base32 = {
|
|
30
|
+
encode,
|
|
31
|
+
};
|
|
32
|
+
export default base32;
|
|
33
|
+
//# sourceMappingURL=base32.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base32.js","sourceRoot":"","sources":["../src/base32.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb;;;;;;GAMG;AAEH;;GAEG;AACH,MAAM,OAAO,GAAG,kCAAkC,CAAC;AAEnD;;;;GAIG;AACH,MAAM,UAAU,MAAM,CAAC,IAAmB;IACxC,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACtB,IAAI,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,KAAK,GAAG,EAAE,CAAC,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CAAC,QAAQ,GAAG,KAAK,CAAC,CAAC;QACpC,CAAC;QACD,MAAM,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC;IAC3B,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,MAAM,GAAG;IACb,MAAM;CACP,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,SAAS,CAAC;AAE5B,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,sBAAsB,CAAC;AAE9B,eAAe,KAAK,CAAC"}
|
package/lib-es/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,SAAS,CAAC;AAE5B,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,sBAAsB,CAAC;AAE9B,eAAe,KAAK,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kaspa-util.d.ts","sourceRoot":"","sources":["../src/kaspa-util.ts"],"names":[],"mappings":";AAiGA,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAS7D"}
|