@secux/app-dash
Advanced tools
Comparing version 2.0.0 to 3.0.0
@@ -1,5 +0,8 @@ | ||
/// <reference types="node" /> | ||
import { SecuxBTC } from "@secux/app-btc"; | ||
declare type T1 = Parameters<typeof SecuxBTC.getAddress>; | ||
declare type T2 = Parameters<typeof SecuxBTC.signTransaction>; | ||
export { txInput, txOutput, txOutputAddress, txOutputScriptExtened } from "@secux/app-btc"; | ||
declare type T1 = Parameters<typeof SecuxBTC.addressConvert>; | ||
declare type T2 = Parameters<typeof SecuxBTC.prepareAddress>; | ||
declare type T3 = Parameters<typeof SecuxBTC.resolveAddress>; | ||
declare type T4 = Parameters<typeof SecuxBTC.prepareSign>; | ||
declare type T5 = Parameters<typeof SecuxBTC.resolveTransaction>; | ||
/** | ||
@@ -10,23 +13,43 @@ * DASH package for SecuX device | ||
/** | ||
* Get address derived by given BIP32 path | ||
* @param {ITransport} trans | ||
* Convert publickey to BTC address | ||
* @param {communicationData} publickey secp256k1 publickey | ||
* @param {string | PathObject} path | ||
* @returns {string} | ||
*/ | ||
static addressConvert(...args: T1): string; | ||
/** | ||
* prepare data for address generation | ||
* @param {string} path BIP32 | ||
* @param {AddressOption} [option] | ||
* @returns {string} address | ||
* @param {AddressOption} [option] option for validating bip32 path | ||
* @returns {communicationData} buffer for send | ||
*/ | ||
static getAddress(...args: T1): Promise<string>; | ||
static prepareAddress(...args: T2): import("@secux/utility/lib/communication").communicationData; | ||
/** | ||
* Create transaction and Sign | ||
* @param {ITransport} trans | ||
* @param {Array<txInput>} inputs | ||
* Resolve address | ||
* @param {communicationData} response | ||
* @param {string | PathObject} path | ||
* @returns {string} | ||
*/ | ||
static resolveAddress(...args: T3): string; | ||
/** | ||
* Prepare data for sign | ||
* @param {txInput} inputs | ||
* @param {txOutput} outputs | ||
* @returns {object} signed | ||
* @returns {string} signed.raw_tx | ||
* @returns {Array<Buffer>} signed.signature | ||
* @returns {object} prepared | ||
* @returns {communicationData} prepared.commandData | ||
* @returns {string} prepared.rawTx | ||
*/ | ||
static signTransaction(...args: T2): Promise<{ | ||
raw_tx: string; | ||
signature: Buffer[]; | ||
}>; | ||
static prepareSign(...args: T4): { | ||
commandData: import("@secux/utility/lib/communication").communicationData; | ||
rawTx: string; | ||
}; | ||
/** | ||
* Serialize transaction wtih signature for broadcast | ||
* @param {communicationData} response | ||
* @param {string} unsigned unsigned raw transaction | ||
* @param {Array<communicationData>} publickeys | ||
* @param {CoinType} [coin] | ||
* @returns {string} signed raw transaction | ||
*/ | ||
static resolveTransaction(...args: T5): string; | ||
} | ||
export {}; |
@@ -1,1 +0,1 @@ | ||
"use strict";var t=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))((function(r,c){function s(t){try{u(i.next(t))}catch(t){c(t)}}function o(t){try{u(i.throw(t))}catch(t){c(t)}}function u(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,o)}u((i=i.apply(t,e||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.SecuxDASH=void 0;const e=require("@secux/app-btc"),n=require("ow"),i=require("@secux/utility"),r=require("@secux/app-btc/lib/interface").coinmap[e.CoinType.DASH].coinType;class c extends e.SecuxBTC{static getAddress(...n){const i=Object.create(null,{getAddress:{get:()=>super.getAddress}});return t(this,void 0,void 0,(function*(){return i.getAddress.call(this,n[0],n[1],{coin:e.CoinType.DASH})}))}static signTransaction(...c){const s=Object.create(null,{signTransaction:{get:()=>super.signTransaction}});return t(this,void 0,void 0,(function*(){for(const t of c[1])(0,n.default)(t.path,(0,i.ow_strictPath)(r,44)),t.script=e.ScriptType.P2PKH;return s.signTransaction.call(this,...c)}))}}exports.SecuxDASH=c; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SecuxDASH=void 0;const e=require("@secux/app-btc"),t=require("ow"),r=require("@secux/utility"),s=require("@secux/app-btc/lib/interface"),o=s.coinmap[s.CoinType.DASH].coinType;class a extends e.SecuxBTC{static addressConvert(...e){return"string"==typeof e[1]?(0,t.default)(e[1],(0,r.ow_strictPath)(o)):e[1].coin=s.CoinType.DASH,super.addressConvert(...e)}static prepareAddress(...e){return(0,t.default)(e[0],(0,r.ow_strictPath)(o)),e[1]&&(e[1].coin=s.CoinType.DASH),super.prepareAddress(...e)}static resolveAddress(...e){return"string"==typeof e[1]?(0,t.default)(e[1],(0,r.ow_strictPath)(o)):e[1].coin=s.CoinType.DASH,super.resolveAddress(...e)}static prepareSign(...e){var s;return e[0].forEach((e=>(0,t.default)(e.path,(0,r.ow_strictPath)(o)))),e[1].to.path&&(0,t.default)(e[1].to.path,(0,r.ow_strictPath)(o)),(null===(s=e[1].utxo)||void 0===s?void 0:s.path)&&(0,t.default)(e[1].utxo.path,(0,r.ow_strictPath)(o)),super.prepareSign(...e)}static resolveTransaction(...e){return e[3]=s.CoinType.DASH,super.resolveTransaction(...e)}}exports.SecuxDASH=a; |
{ | ||
"name": "@secux/app-dash", | ||
"version": "2.0.0", | ||
"version": "3.0.0", | ||
"description": "SecuX Hardware Wallet DASH API", | ||
@@ -30,4 +30,4 @@ "keywords": [ | ||
"dependencies": { | ||
"@secux/app-btc": "latest" | ||
"@secux/app-btc": "^3.0.0" | ||
} | ||
} |
133
README.md
@@ -8,6 +8,6 @@ # `@secux/app-dash` | ||
```ts | ||
import { SecuxDASH, ScriptType } from "@secux/app-dash"; | ||
import { SecuxDASH } from "@secux/app-dash"; | ||
``` | ||
First, create instance of ITransport | ||
First, create instance of ITransport. | ||
- [Web Usb](https://www.npmjs.com/package/@secux/transport-webusb) | ||
@@ -20,29 +20,27 @@ - [Web Bluetooth](https://www.npmjs.com/package/@secux/transport-webble) | ||
## Examples | ||
1. Get address by BIP32 path | ||
```ts | ||
// native segwit address (default script: P2WPKH) | ||
const address = SecuxDASH.getAddress( | ||
device, | ||
"m/84'/5'/0'/0/0", | ||
// optional object | ||
{ | ||
// define specific script | ||
script: ScriptType.P2WPKH | ||
} | ||
); | ||
1. Get address by BIP32 path. | ||
- native segwit address (default script: P2WPKH) | ||
```ts | ||
const path = "m/84'/5'/0'/0/0"; | ||
const address = await device.getAddress(path); | ||
// segwit address (default script: P2SH_P2WPKH) | ||
const address = SecuxDASH.getAddress( | ||
device, | ||
"m/49'/5'/0'/0/0" | ||
); | ||
/* | ||
// legacy address (default script: P2PKH) | ||
const address = SecuxDASH.getAddress( | ||
device, | ||
"m/44'/5'/0'/0/0" | ||
); | ||
``` | ||
// transfer data to hardware wallet by custom transport layer. | ||
const data = SecuxDASH.prepareAddress(path); | ||
const response = await device.Exchange(data); | ||
const address = SecuxDASH.resolveAddress(response, path); | ||
2. sign transaction (support legacy transaction currently) | ||
*/ | ||
``` | ||
- segwit address (default script: P2SH_P2WPKH) | ||
```ts | ||
const address = await device.getAddress("m/49'/5'/0'/0/0"); | ||
``` | ||
- legacy address (default script: P2PKH) | ||
```ts | ||
const address = await device.getAddress("m/44'/5'/0'/0/0"); | ||
``` | ||
2. Sign transaction (support legacy transaction currently). | ||
```ts | ||
@@ -53,6 +51,6 @@ const inputs = [ | ||
vout: 0, | ||
// for p2pkh, the raw transaction of utxo is needed | ||
txHex: "01000000014dbd59d6ed38562107fbeb0220e31edb8c1ba8b73a34b2f824f512a24b3cbf91010000006b483045022100fa1bd6657fe88fb2b830c40b2841f7a6bfa3f154ad5913ff4aea1e2d3e139a0802207f43cb96d1cd5aa0744cb5092b01ab807fa800a798443f10ed590610925ca7160121025abaf3afa351406dc55d646c40da53c0f2fe9736ebcf6fca232a122c21b6c897ffffffff02a0860100000000001976a914c9340fea78f10172d839a2c6f4fa38dda161ef5588ac7a499300000000001976a914784ab02b6007b8847900a3543f53b597482d52a288ac00000000", | ||
satoshis: 100000, | ||
path: "m/44'/5'/0'/0/0" | ||
path: "m/44'/5'/0'/0/0", | ||
// for custom transport layer, each utxo need publickey. | ||
// publickey: "026fa9a6f213b6ba86447965f6b4821264aaadd7521f049f00db9c43a770ea7405" | ||
}, | ||
@@ -62,10 +60,10 @@ { | ||
vout: 0, | ||
// for p2pkh, the raw transaction of utxo is needed | ||
txHex: "010000000106f0f36dc6ca008844b02e35f8f61eff042bc2dc95c03ed9555a652e504b4b25000000006b483045022100cf8c5e46bc32224a2bbac92e1fc45bbfe568dd4ea73176f5d78b4dac1e90e023022019efabf3c096a00c54d8073dc452defb826498bb230ca83b966ae94705ce6975012102b92ed8814ae5dc22c33ff0049aed40d8b9d98eaef09ac555e2f86fbb9fe7aa49ffffffff01b0840100000000001976a9145f2595bafb0ce9c9869963fb67b9100bd2235f9e88ac00000000", | ||
satoshis: 99504, | ||
path: "m/44'/5'/2'/0/0" | ||
path: "m/44'/5'/2'/0/0", | ||
// for custom transport layer, each utxo need publickey. | ||
// publickey: "033bf91bf2d1798e11c09c6523a92bbe9d0fbde3b62af0daea97beaa51a05b0d31" | ||
} | ||
]; | ||
const out = { | ||
const to = { | ||
address: "XefQmd7TDrF8cMUqTBuP5FUfA1frnUc8pW", | ||
@@ -75,65 +73,22 @@ satoshis: 99999 | ||
// or send to another account | ||
// const out = { | ||
// path: "m/44'/5'/2'/0/2", | ||
// satoshis: 99999 | ||
// }; | ||
const utxo = { | ||
path: "m/44'/5'/3'/0/4", | ||
satoshis: 88888 | ||
satoshis: 88888, | ||
// for custom transport layer, each utxo need publickey. | ||
// publickey: "02df0a5e4d0a03f70452f236c83995b5e37033931dab340b2570132ee727f9427b" | ||
}; | ||
const { raw_tx } = await device.sign(inputs, { to, utxo }); | ||
const { raw_tx, signature } = await SecuxDASH.signTransaction( | ||
device, | ||
inputs, | ||
{ | ||
to: out, | ||
utxo: utxo | ||
} | ||
); | ||
/* | ||
// transfer data to hardware wallet by custom transport layer. | ||
const { commandData, rawTx } = SecuxDASH.prepareSign(inputs, { to, utxo }); | ||
const response = await device.Exchange(commandData); | ||
const signed = SecuxDASH.resloveTransaction(response, rawTx, inputs.map(x => x.publickey)); | ||
*/ | ||
``` | ||
## API doc | ||
<a name="SecuxDASH"></a> | ||
### `SecuxDASH` | ||
DASH package for SecuX device | ||
**Kind**: global class | ||
- [SecuxDASH](#secuxdash) | ||
- [**SecuxDASH.getAddress(trans, path, [option])** ⇒ <code>string</code>](#secuxdashgetaddresstrans-path-option--string) | ||
- [**SecuxDASH.signTransaction(trans, inputs, outputs)** ⇒ <code>object</code>](#secuxdashsigntransactiontrans-inputs-outputs--object) | ||
<a name="SecuxDASH.getAddress"></a><br/> | ||
### **SecuxDASH.getAddress(trans, path, [option])** ⇒ <code>string</code> | ||
*Get address derived by given BIP32 path* | ||
**Kind**: static method of [<code>SecuxDASH</code>](#SecuxDASH) | ||
**Returns**: <code>string</code> - address | ||
| Param | Type | Description | | ||
| --- | --- | --- | | ||
| trans | <code>ITransport</code> | | | ||
| path | <code>string</code> | BIP32 | | ||
| [option] | <code>AddressOption</code> | | | ||
<a name="SecuxDASH.signTransaction"></a><br/> | ||
### **SecuxDASH.signTransaction(trans, inputs, outputs)** ⇒ <code>object</code> | ||
*Create transaction and Sign* | ||
**Kind**: static method of [<code>SecuxDASH</code>](#SecuxDASH) | ||
**Returns**: <code>object</code> - signed<br/> | ||
<code>string</code> - signed.raw_tx<br/> | ||
<code>Array<Buffer></code> - signed.signature<br/> | ||
| Param | Type | | ||
| --- | --- | | ||
| trans | <code>ITransport</code> | | ||
| inputs | <code>Array<txInput></code> | | ||
| outputs | <code>txOutput</code> | | ||
Similar to [@secux/app-btc](https://www.npmjs.com/package/@secux/app-btc). |
54
6360
89
Updated@secux/app-btc@^3.0.0