Socket
Socket
Sign inDemoInstall

@secux/app-grs

Package Overview
Dependencies
36
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0 to 3.0.0

59

lib/app-grs.d.ts

@@ -1,6 +0,8 @@

/// <reference types="node" />
import { SecuxBTC } from "@secux/app-btc";
export { txInput, txOutput, txOutputAddress, txOutputScriptExtened } from "@secux/app-btc";
declare type T1 = Parameters<typeof SecuxBTC.getAddress>;
declare type T2 = Parameters<typeof SecuxBTC.signTransaction>;
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>;
/**

@@ -11,22 +13,43 @@ * GRS 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: Array<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;
}

@@ -1,1 +0,1 @@

"use strict";var t=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))((function(c,r){function s(t){try{u(i.next(t))}catch(t){r(t)}}function o(t){try{u(i.throw(t))}catch(t){r(t)}}function u(t){var e;t.done?c(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.SecuxGRS=void 0;const e=require("@secux/app-btc"),n=require("ow"),i=require("@secux/app-btc/lib/interface"),c=require("@secux/utility"),r=i.coinmap[i.CoinType.GROESTL].coinType,s=c.supported_coin.find((t=>t.cointype===r));class o extends e.SecuxBTC{static getAddress(...e){const n=Object.create(null,{getAddress:{get:()=>super.getAddress}});return t(this,void 0,void 0,(function*(){return n.getAddress.call(this,e[0],e[1],{coin:i.CoinType.GROESTL})}))}static signTransaction(...e){const i=Object.create(null,{signTransaction:{get:()=>super.signTransaction}});return t(this,void 0,void 0,(function*(){for(const t of e[1])(0,n.default)(t.path,(0,c.ow_strictPath)(s.cointype,s.purpose));return i.signTransaction.call(this,...e)}))}}exports.SecuxGRS=o;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.SecuxGRS=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.GROESTL].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.GROESTL,super.addressConvert(...e)}static prepareAddress(...e){return(0,t.default)(e[0],(0,r.ow_strictPath)(o)),e[1]&&(e[1].coin=s.CoinType.GROESTL),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.GROESTL,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.GROESTL,super.resolveTransaction(...e)}}exports.SecuxGRS=a;
{
"name": "@secux/app-grs",
"version": "2.0.0",
"version": "3.0.0",
"description": "SecuX Hardware Wallet GRS API",

@@ -31,4 +31,4 @@ "keywords": [

"dependencies": {
"@secux/app-btc": "latest"
"@secux/app-btc": "^3.0.0"
}
}

@@ -8,6 +8,6 @@ # `@secux/app-grs`

```ts
import { SecuxGRS, ScriptType } from "@secux/app-grs";
import { SecuxGRS } from "@secux/app-grs";
```
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 = SecuxGRS.getAddress(
device,
"m/84'/17'/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'/17'/0'/0/0";
const address = await device.getAddress(path);
// segwit address (default script: P2SH_P2WPKH)
const address = SecuxGRS.getAddress(
device,
"m/49'/17'/0'/0/0"
);
/*
// legacy address (default script: P2PKH)
const address = SecuxGRS.getAddress(
device,
"m/44'/17'/0'/0/0"
);
```
// transfer data to hardware wallet by custom transport layer.
const data = SecuxGRS.prepareAddress(path);
const response = await device.Exchange(data);
const address = SecuxGRS.resolveAddress(response, path);
2. sign transaction (native segwit has not supported yet)
*/
```
- segwit address (default script: P2SH_P2WPKH)
```ts
const address = await device.getAddress("m/49'/17'/0'/0/0");
```
- legacy address (default script: P2PKH)
```ts
const address = await device.getAddress("m/44'/17'/0'/0/0");
```
2. Sign transaction (native segwit has not supported yet).
```ts

@@ -53,6 +51,6 @@ const inputs = [

vout: 0,
// for p2pkh, the raw transaction of utxo is needed
txHex: "01000000000102b0250046e7c8fc7a4428f890adf03f6cfbdeba36c5f31bb7b78e98b0327c45a1010000001716001470454cee54d0f3966f4769f22b89f00c7854760dffffffff0b7352b50d6b23c361dadf54651b3f77d1e3d06863ff932572ecae0af07c78610000000017160014aec71b817cafed717c93216c420b64cdf004d087ffffffff01ea29341d000000001976a9142f77ebea597a50930b099e1b1d95244a788dff7188ac0247304402207605a44c8c7ab14e201d55391841f30a556eebd6dcbb0c6a8fe6f0f3ee7fb63102200a57c212e582001f5c220cf980b61141073dc9c0c9519da331247a1fcb83e6f40121027e61de977f7ff3432336ebe518c9b3cbd6090bf7947894804b54242b47b9e77402483045022100e10ef1e61689ad3b3ba21b3a15d1eae6ad2538d47e29ab6c453efb16a28b89da0220312d67075914b0d90bb1c6e99284b107e97e05bd5c908c883f0e9e189688b1ff012103abeffd221d762b07581fd06122507257fd18bd18fa7f66c1138beb793f7a4fc000000000",
satoshis: 489957866,
path: "m/44'/17'/0'/0/0"
path: "m/44'/17'/0'/0/0",
// for custom transport layer, each utxo need publickey.
// publickey: "030f25e157a5ddc119bf370beb688878a3600461eb5c769a5556bdfe225d9a246e"
},

@@ -63,7 +61,9 @@ {

satoshis: 1000000,
path: "m/49'/17'/0'/0/0"
path: "m/49'/17'/0'/0/0",
// for custom transport layer, each utxo need publickey.
// publickey: "0212f4f7e43bae1bc53ef94dbef85f8348550975f5fd8f3693c19757223692e8dd"
}
];
const out = {
const to = {
address: "38kpyoty76H1c6wWo7cfbPYNB88RsMV8AB",

@@ -73,65 +73,22 @@ satoshis: 400000000

// or send to another account
// const out = {
// path: "m/49'/17'/2'/0/2",
// satoshis: 400000000
// }
const utxo = {
path: `m/44'/17'/0'/0/7`,
satoshis: 60000000,
// for custom transport layer, each utxo need publickey.
// publickey: "0270806ba59d0abe13f6a0a13d2997f358fca3de938aec7f52bc78e7121d24ae23"
}
const { raw_tx } = await device.sign(inputs, { to, utxo });
const { raw_tx, signature } = await SecuxGRS.signTransaction(
device,
inputs,
{
to: out,
utxo: utxo
}
);
/*
// transfer data to hardware wallet by custom transport layer.
const { commandData, rawTx } = SecuxGRS.prepareSign(inputs, { to, utxo });
const response = await device.Exchange(commandData);
const signed = SecuxGRS.resloveTransaction(response, rawTx, inputs.map(x => x.publickey));
*/
```
## API doc
<a name="SecuxGRS"></a>
### `SecuxGRS`
GRS package for SecuX device
**Kind**: global class
- [SecuxGRS](#secuxgrs)
- [**SecuxGRS.getAddress(trans, path, [option])** ⇒ <code>string</code>](#secuxgrsgetaddresstrans-path-option--string)
- [**SecuxGRS.signTransaction(trans, inputs, outputs)** ⇒ <code>object</code>](#secuxgrssigntransactiontrans-inputs-outputs--object)
<a name="SecuxGRS.getAddress"></a><br/>
### **SecuxGRS.getAddress(trans, path, [option])** ⇒ <code>string</code>
*Get address derived by given BIP32 path*
**Kind**: static method of [<code>SecuxGRS</code>](#SecuxGRS)
**Returns**: <code>string</code> - address
| Param | Type | Description |
| --- | --- | --- |
| trans | <code>ITransport</code> | |
| path | <code>string</code> | BIP32 |
| [option] | <code>AddressOption</code> | |
<a name="SecuxGRS.signTransaction"></a><br/>
### **SecuxGRS.signTransaction(trans, inputs, outputs)** ⇒ <code>object</code>
*Create transaction and Sign*
**Kind**: static method of [<code>SecuxGRS</code>](#SecuxGRS)
**Returns**: <code>object</code> - signed<br/>
<code>string</code> - signed.raw_tx<br/>
<code>Array&lt;Buffer&gt;</code> - signed.signature<br/>
| Param | Type |
| --- | --- |
| trans | <code>ITransport</code> |
| inputs | <code>Array&lt;txInput&gt;</code> |
| outputs | <code>txOutput</code> |
Similar to [@secux/app-btc](https://www.npmjs.com/package/@secux/app-btc).
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc