Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@secux/app-ada

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@secux/app-ada - npm Package Compare versions

Comparing version 3.0.1 to 3.0.2

119

lib/app-ada.d.ts

@@ -23,3 +23,3 @@ /// <reference types="node" />

*/
static readonly prepareAddress: typeof SecuxADA.prepareXPublickey;
static prepareAddress(pathWith3Depth: string): communicationData;
/**

@@ -69,2 +69,9 @@ * Resolve address from response data.

static resolveTransaction(response: communicationData, serialized: communicationData): string;
/**
* Prepare data for signing.
* @param {stakeInput} input
* @param {string} pool pool hash or id
* @param {stakeOption} [option]
* @returns {prepared}
*/
static prepareStake(input: stakeInput, pool: string, option?: stakeOption): {

@@ -74,2 +81,8 @@ commandData: communicationData;

};
/**
* Prepare data for signing.
* @param {stakeInput} input
* @param {unstakeOption} [option]
* @returns {prepared}
*/
static prepareUnstake(input: stakeInput, option?: unstakeOption): {

@@ -79,2 +92,9 @@ commandData: communicationData;

};
/**
* Prepare data for signing.
* @param {stakeInput} input
* @param {number | string} amount rewards
* @param {withdrawOption} [option]
* @returns {prepared}
*/
static prepareWithdraw(input: stakeInput, amount: number | string, option?: withdrawOption): {

@@ -100,1 +120,98 @@ commandData: communicationData;

}
/**
* Data type for transmission.
* @typedef {string | Buffer} communicationData
*/
/**
* Address type. (BASE ~ REWARD: Shelley-type)
* @typedef {enum} AddressType
* @property {number} BASE 0
* @property {number} ENTERPRISE 1
* @property {number} POINTER 2
* @property {number} REWARD 3
* @property {number} BOOTSTRAPv1 4
* @property {number} BOOTSTRAPv2 5
*/
/**
* Parameters of Pointer address.
* @typedef {object} PointerOption
* @property {number} slot
* @property {number} txIndex
* @property {number} certIndex
*/
/**
* Options for generating address.
* @typedef {object} AddressOption
* @property {number} [addressIndex] account index
* @property {number} [stakeIndex] stake key index
* @property {PointerOption} [pointer] option for Pointer address
*/
/**
* The UTXO object.
* @typedef {object} txInput
* @property {string} path 3-depth path of CIP-1852
* @property {string | Buffer} xpublickey ED25519 publickey from `path`
* @property {string} txId referenced transaction hash
* @property {number} index referenced transaction output index
* @property {number | string} amount referenced transaction output amount
* @property {number} [addressIndex] default: 0
* @property {number} [stakeIndex] default: 0
*/
/**
* The payment object.
* @typedef {object} txOutput
* @property {string} address receiver's address
* @property {number | string} amount amount of payment
*/
/**
* Option for payment.
* @typedef {object} signOption
* @property {string} [changeAddress] default: sender's address
* @property {number | string} [fee]
* @property {number} [TimeToLive]
*/
/**
* Option for staking.
* @typedef {object} stakeOption
* @property {number} [stakeIndex] default: 0
* @property {boolean} [needRegistration] include registration or not
* @property {number | string} [fee]
* @property {number} [TimeToLive]
*/
/**
* Option for withdraw rewards.
* @typedef {object} withdrawOption
* @property {number} [stakeIndex] default: 0
* @property {number | string} [fee]
* @property {number} [TimeToLive]
*/
/**
* Option for unstaking. (de-registration)
* @typedef {object} unstakeOption
* @property {number} [stakeIndex] default: 0
* @property {boolean} [withdrawAmount] withdraw and de-registration
* @property {number | string} [fee]
* @property {number} [TimeToLive]
*/
/**
* @typedef {object} utxo
* @property {string} txId referenced transaction hash
* @property {number} index referenced transaction output index
* @property {number | string} amount referenced transaction output amount
* @property {number} [addressIndex] default: 0
*/
/**
* Parameters for staking operations.
* @typedef {object} stakeInput
* @property {string} path 3-depth path of CIP-1852
* @property {Array<utxo>} utxo
* @property {string} changeAddress owner's account
* @property {string | Buffer} xpublickey cardano bip32-publickey
* @property {number} [stakeIndex] default: 0
*/
/**
* Object for the signing and validation.
* @typedef {object} prepared
* @property {communicationData} commandData data for sending to device
* @property {communicationData} serialized
*/

2

lib/app-ada.js

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

"use strict";var e,t=this&&this.__decorate||function(e,t,r,a){var n,o=arguments.length,i=o<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,r):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,r,a);else for(var s=e.length-1;s>=0;s--)(n=e[s])&&(i=(o<3?n(i):o>3?n(t,r,i):n(t,r))||i);return o>3&&i&&Object.defineProperty(t,r,i),i},r=this&&this.__awaiter||function(e,t,r,a){return new(r||(r=Promise))((function(n,o){function i(e){try{d(a.next(e))}catch(e){o(e)}}function s(e){try{d(a.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,s)}d((a=a.apply(e,t||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.AddressType=exports.SecuxADA=void 0;const a=require("./load_lib"),n=require("cardano-crypto.js"),o=require("@secux/utility/lib/communication"),i=require("./interface");Object.defineProperty(exports,"AddressType",{enumerable:!0,get:function(){return i.AddressType}});const s=require("@secux/protocol-transaction"),d=require("@secux/protocol-transaction/lib/interface"),c=require("ow"),u=require("@secux/utility"),l=require("@secux/transport"),f=null===u.Logger||void 0===u.Logger?void 0:u.Logger.child({id:"ada"});let p=e=class{static addressConvert(e,t,r){var o,s,d;(0,c.default)(e,i.ow_xpublickey),(0,c.default)(t,c.default.number.inRange(0,i.AddressType.__LENGTH-1)),(0,c.default)(r,c.default.any(c.default.undefined,i.ow_AddressOption));const u=h(e),l=a.cardano.Bip32PublicKey.from_bytes(u),f=l.derive(0).derive(null!==(o=null==r?void 0:r.addressIndex)&&void 0!==o?o:0),p=l.derive(2).derive(null!==(s=null==r?void 0:r.stakeIndex)&&void 0!==s?s:0);switch(t){case i.AddressType.BOOTSTRAPv1:const{pbkdf2Sync:e}=require("pbkdf2"),o=e(u,"address-hashing",500,32,"sha512");return n.base58.encode(n.packBootstrapAddress([2147483648,2147483648|(null!==(d=null==r?void 0:r.addressIndex)&&void 0!==d?d:0)],u,o,1,a.cardano.NetworkInfo.mainnet().protocol_magic()));case i.AddressType.BOOTSTRAPv2:return a.cardano.ByronAddress.icarus_from_key(f,a.cardano.NetworkInfo.mainnet().protocol_magic()).to_base58();case i.AddressType.BASE:return a.cardano.BaseAddress.new(a.cardano.NetworkInfo.mainnet().network_id(),a.cardano.StakeCredential.from_keyhash(f.to_raw_key().hash()),a.cardano.StakeCredential.from_keyhash(p.to_raw_key().hash())).to_address().to_bech32();case i.AddressType.ENTERPRISE:return a.cardano.EnterpriseAddress.new(a.cardano.NetworkInfo.mainnet().network_id(),a.cardano.StakeCredential.from_keyhash(f.to_raw_key().hash())).to_address().to_bech32();case i.AddressType.POINTER:const s=r.pointer;return(0,c.default)(s,i.ow_PointerOption),a.cardano.PointerAddress.new(a.cardano.NetworkInfo.mainnet().network_id(),a.cardano.StakeCredential.from_keyhash(f.to_raw_key().hash()),a.cardano.Pointer.new(s.slot,s.txIndex,s.certIndex)).to_address().to_bech32();case i.AddressType.REWARD:return a.cardano.RewardAddress.new(a.cardano.NetworkInfo.mainnet().network_id(),a.cardano.StakeCredential.from_keyhash(p.to_raw_key().hash())).to_address().to_bech32();default:throw Error(`ArgumentError: unsupported address type, got ${i.AddressType[t]}`)}}static resolveAddress(t,r,a){(0,c.default)(r,c.default.number.inRange(0,i.AddressType.__LENGTH));const n=e.resolveXPublickey(t);return e.addressConvert(n,r,a)}static prepareXPublickey(e){return(0,c.default)(e,i.ow_path),s.SecuxTransactionTool.getXPublickey(e,d.EllipticCurve.ED25519_ADA)}static resolveXPublickey(e){return s.SecuxTransactionTool.resolveXPublickey(e,void 0,d.EllipticCurve.ED25519_ADA)}static prepareSign(e,t,r){(0,c.default)(e,c.default.array.ofType(i.ow_txInput)),(0,c.default)(t,i.ow_txOutput),(0,c.default)(r,c.default.any(c.default.undefined,i.ow_signOption));const o=t.address.startsWith("DdzFF")?a.cardano.__byronConfig:a.cardano.__config,{builder:s,paths:d,publickeys:u}=y(e,o);let l;try{l=a.cardano.Address.from_bech32(t.address)}catch(e){l=a.cardano.Address.from_bytes(n.base58.decode(t.address))}s.add_output(a.cardano.TransactionOutput.new(l,a.cardano.Value.new(a.cardano.BigNum.from_str(t.amount.toString(10)))));return b(d,u,g(s,r))}static resolveSignatureList(e){return s.SecuxTransactionTool.resolveSignatureList(e).map((e=>Buffer.from(e,"base64"))).map((e=>u.Signature.fromSignature(e))).map((e=>Buffer.concat([e.r,e.s]).toString("hex")))}static resolveTransaction(t,r){(0,c.default)(r,o.ow_communicationData);const n=JSON.parse((0,o.getBuffer)(r).toString()),i=e.resolveSignatureList(t),s=a.cardano.TransactionBody.from_bytes(Buffer.from(n.rawTx,"hex")),d=a.cardano.Vkeywitnesses.new();for(let e=0;e<i.length;e++){const t=a.cardano.PublicKey.from_bytes(h(n.publickeys[e])),r=a.cardano.Ed25519Signature.from_hex(i[e]);if(!t.verify(a.cardano.hash_transaction(s).to_bytes(),r))throw null==f||f.error(`signature error, got signature ${i[e]} and publickey ${n.publickeys[e]}`),Error(`Signature error #${e}`);d.add(a.cardano.Vkeywitness.new(a.cardano.Vkey.new(t),r))}const u=a.cardano.TransactionWitnessSet.new();u.set_vkeys(d);const l=a.cardano.Transaction.new(s,u);if(!l.is_valid()){null==f||f.debug(`Cannot finalize transaction, tx: ${n.rawTx}\n`);for(let e=0;e<i.length;e++)null==f||f.debug(`signature#${e}: ${i[e]}`);throw Error("Cannot finalize transaction.")}return Buffer.from(l.to_bytes()).toString("base64")}static prepareStake(e,t,r){var n;(0,c.default)(e,i.ow_stakeInput),(0,c.default)(t,c.default.any(i.ow_poolHash,u.ow_hexString.length(56))),(0,c.default)(r,c.default.any(c.default.undefined,i.ow_stakeOption));const o=null!==(n=null==r?void 0:r.stakeIndex)&&void 0!==n?n:0,s=_(h(e.xpublickey),2,o),d=a.cardano.StakeCredential.from_keyhash(a.cardano.PublicKey.from_bytes(s).hash()),l=a.cardano.Certificates.new();(null==r?void 0:r.needRegistration)&&l.add(a.cardano.Certificate.new_stake_registration(a.cardano.StakeRegistration.new(d))),l.add(a.cardano.Certificate.new_stake_delegation(a.cardano.StakeDelegation.new(d,t.startsWith("pool")?a.cardano.Ed25519KeyHash.from_bech32(t):a.cardano.Ed25519KeyHash.from_bytes(Buffer.from(t,"hex")))));const f=e.utxo.map((t=>Object.assign({path:e.path,xpublickey:e.xpublickey},t))),{builder:p,paths:w,publickeys:k}=y(f);p.set_certs(l),w.push(`${e.path}/2/${o}`),k.push(s);return b(w,k,g(p,{fee:null==r?void 0:r.fee,TimeToLive:null==r?void 0:r.TimeToLive,changeAddress:e.changeAddress}))}static prepareUnstake(e,t){var r;(0,c.default)(e,i.ow_stakeInput),(0,c.default)(t,c.default.any(c.default.undefined,i.ow_unstakeOption));const n=null!==(r=null==t?void 0:t.stakeIndex)&&void 0!==r?r:0,o=_(h(e.xpublickey),2,n),s=a.cardano.StakeCredential.from_keyhash(a.cardano.PublicKey.from_bytes(o).hash()),d=a.cardano.Certificates.new();d.add(a.cardano.Certificate.new_stake_deregistration(a.cardano.StakeDeregistration.new(s)));const u=e.utxo.map((t=>Object.assign({path:e.path,xpublickey:e.xpublickey},t))),{builder:l,paths:f,publickeys:p}=y(u);if(l.set_certs(d),null==t?void 0:t.withdrawAmount){const e=a.cardano.Withdrawals.new();e.insert(a.cardano.RewardAddress.new(a.cardano.NetworkInfo.mainnet().network_id(),s),a.cardano.BigNum.from_str(t.withdrawAmount.toString(10))),l.set_withdrawals(e)}f.push(`${e.path}/2/${n}`),p.push(o);return b(f,p,g(l,{fee:null==t?void 0:t.fee,TimeToLive:null==t?void 0:t.TimeToLive,changeAddress:e.changeAddress}))}static prepareWithdraw(e,t,r){var n;(0,c.default)(e,i.ow_stakeInput),(0,c.default)(t,c.default.any(c.default.number.uint32.positive,u.ow_numberString)),(0,c.default)(r,c.default.any(c.default.undefined,i.ow_withdrawOption));const o=null!==(n=null==r?void 0:r.stakeIndex)&&void 0!==n?n:0,s=_(h(e.xpublickey),2,o),d=a.cardano.StakeCredential.from_keyhash(a.cardano.PublicKey.from_bytes(s).hash()),l=a.cardano.Withdrawals.new();l.insert(a.cardano.RewardAddress.new(a.cardano.NetworkInfo.mainnet().network_id(),d),a.cardano.BigNum.from_str(t.toString(10)));const f=e.utxo.map((t=>Object.assign({path:e.path,xpublickey:e.xpublickey},t))),{builder:p,paths:w,publickeys:k}=y(f);p.set_withdrawals(l),w.push(`${e.path}/2/${o}`),k.push(s);return b(w,k,g(p,{fee:null==r?void 0:r.fee,TimeToLive:null==r?void 0:r.TimeToLive,changeAddress:e.changeAddress}))}static getAddress(t,a,n){return r(this,void 0,void 0,(function*(){const r=e.prepareAddress(t),i=yield this.Exchange((0,o.getBuffer)(r));return e.resolveAddress(i,a,n)}))}static getPublickey(t,a=!0){return r(this,void 0,void 0,(function*(){(0,c.default)(t,i.ow_fullPath);const r=t.match(/\d+/g),n=e.prepareXPublickey(`m/${r[0]}'/${r[1]}'/${r[2]}'`),s=yield this.Exchange((0,o.getBuffer)(n));return _(h(e.resolveXPublickey(s)),parseInt(r[3],10),parseInt(r[4],10),a).toString("hex")}))}static getXPublickey(t){return r(this,void 0,void 0,(function*(){const r=e.prepareXPublickey(t),a=yield this.Exchange((0,o.getBuffer)(r));return e.resolveXPublickey(a)}))}static sign(...t){return r(this,void 0,void 0,(function*(){let r=e.prepareSign;if(Array.isArray(t[0])){const a={};for(const r of t[0])(0,c.default)(r.path,i.ow_path),a[r.path]||(a[r.path]=yield e.getXPublickey.call(this,r.path)),r.xpublickey=a[r.path];r=e.prepareSign}else t[0].xpublickey=yield e.getXPublickey.call(this,t[0].path),r=void 0===t[1]||"object"==typeof t[1]?e.prepareUnstake:"string"!=typeof t[1]||!t[1].startsWith("pool")&&56!==t[1].length?e.prepareWithdraw:e.prepareStake;const{commandData:a,serialized:n}=r(...t),s=yield this.Exchange((0,o.getBuffer)(a));return{raw_tx:e.resolveTransaction(s,n)}}))}};function h(e){return"string"==typeof e?Buffer.from(e,"hex"):e}function _(e,t,r,o=!0){if(o){const a=n.derivePublic(e,t,2),o=n.derivePublic(a,r,2);return Buffer.from(o.slice(0,32))}const i=a.cardano.Bip32PublicKey.from_bytes(e);return Buffer.from(i.derive(t).derive(r).as_bytes().slice(0,32))}function y(e,t){var r;const n=null!=t?t:a.cardano.__config,o=a.cardano.TransactionBuilder.new(...n),i=[],s=[];for(const t of e){const e=null!==(r=t.addressIndex)&&void 0!==r?r:0,n=_(h(t.xpublickey),0,e),d=a.cardano.TransactionInput.new(a.cardano.TransactionHash.from_bytes(Buffer.from(t.txId,"hex")),t.index),c=a.cardano.Value.new(a.cardano.BigNum.from_str(t.amount.toString(10)));o.add_key_input(a.cardano.PublicKey.from_bytes(n).hash(),d,c),i.push(`${t.path}/0/${e}`),s.push(n)}return{builder:o,paths:i,publickeys:s}}function g(e,t){t?(t.fee?e.set_fee(a.cardano.BigNum.from_str(t.fee.toString(10))):t.changeAddress&&e.add_change_if_needed(a.cardano.Address.from_bech32(t.changeAddress)),t.TimeToLive&&e.set_ttl(t.TimeToLive)):e.set_fee(e.min_fee());const r=Buffer.from(e.build().to_bytes()),n=parseInt(e.get_fee_if_set().to_str(),10),o=(i=r.length,a.cardano.__fee_a*i+a.cardano.__fee_b);var i;if(n<o)throw Error(`minimal transaction fee is ${o}, but got ${n}.`);return r}function b(e,t,r){const a=e.map((e=>r)),n=s.SecuxTransactionTool.signRawTransactionList(e,a,void 0,{tp:d.TransactionType.NORMAL,curve:d.EllipticCurve.ED25519_ADA,chainId:0}),i={rawTx:r.toString("hex"),publickeys:t.map((e=>e.toString("hex")))},c=Buffer.from(JSON.stringify(i));return{commandData:n,serialized:(0,o.toCommunicationData)(c)}}p.prepareAddress=e.prepareXPublickey,p=e=t([(0,l.staticImplements)()],p),exports.SecuxADA=p,(0,l.loadPlugin)(p,"SecuxADA");
"use strict";var e,t=this&&this.__decorate||function(e,t,r,a){var n,o=arguments.length,i=o<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,r):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,r,a);else for(var s=e.length-1;s>=0;s--)(n=e[s])&&(i=(o<3?n(i):o>3?n(t,r,i):n(t,r))||i);return o>3&&i&&Object.defineProperty(t,r,i),i},r=this&&this.__awaiter||function(e,t,r,a){return new(r||(r=Promise))((function(n,o){function i(e){try{d(a.next(e))}catch(e){o(e)}}function s(e){try{d(a.throw(e))}catch(e){o(e)}}function d(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,s)}d((a=a.apply(e,t||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.AddressType=exports.SecuxADA=void 0;const a=require("./load_lib"),n=require("cardano-crypto.js"),o=require("@secux/utility/lib/communication"),i=require("./interface");Object.defineProperty(exports,"AddressType",{enumerable:!0,get:function(){return i.AddressType}});const s=require("@secux/protocol-transaction"),d=require("@secux/protocol-transaction/lib/interface"),c=require("ow"),u=require("@secux/utility"),l=require("@secux/transport"),f=null===u.Logger||void 0===u.Logger?void 0:u.Logger.child({id:"ada"});let p=e=class{static addressConvert(e,t,r){var o,s,d;(0,c.default)(e,i.ow_xpublickey),(0,c.default)(t,c.default.number.inRange(0,i.AddressType.__LENGTH-1)),(0,c.default)(r,c.default.any(c.default.undefined,i.ow_AddressOption));const u=h(e),l=a.cardano.Bip32PublicKey.from_bytes(u),f=l.derive(0).derive(null!==(o=null==r?void 0:r.addressIndex)&&void 0!==o?o:0),p=l.derive(2).derive(null!==(s=null==r?void 0:r.stakeIndex)&&void 0!==s?s:0);switch(t){case i.AddressType.BOOTSTRAPv1:const{pbkdf2Sync:e}=require("pbkdf2"),o=e(u,"address-hashing",500,32,"sha512");return n.base58.encode(n.packBootstrapAddress([2147483648,2147483648|(null!==(d=null==r?void 0:r.addressIndex)&&void 0!==d?d:0)],u,o,1,a.cardano.NetworkInfo.mainnet().protocol_magic()));case i.AddressType.BOOTSTRAPv2:return a.cardano.ByronAddress.icarus_from_key(f,a.cardano.NetworkInfo.mainnet().protocol_magic()).to_base58();case i.AddressType.BASE:return a.cardano.BaseAddress.new(a.cardano.NetworkInfo.mainnet().network_id(),a.cardano.StakeCredential.from_keyhash(f.to_raw_key().hash()),a.cardano.StakeCredential.from_keyhash(p.to_raw_key().hash())).to_address().to_bech32();case i.AddressType.ENTERPRISE:return a.cardano.EnterpriseAddress.new(a.cardano.NetworkInfo.mainnet().network_id(),a.cardano.StakeCredential.from_keyhash(f.to_raw_key().hash())).to_address().to_bech32();case i.AddressType.POINTER:const s=r.pointer;return(0,c.default)(s,i.ow_PointerOption),a.cardano.PointerAddress.new(a.cardano.NetworkInfo.mainnet().network_id(),a.cardano.StakeCredential.from_keyhash(f.to_raw_key().hash()),a.cardano.Pointer.new(s.slot,s.txIndex,s.certIndex)).to_address().to_bech32();case i.AddressType.REWARD:return a.cardano.RewardAddress.new(a.cardano.NetworkInfo.mainnet().network_id(),a.cardano.StakeCredential.from_keyhash(p.to_raw_key().hash())).to_address().to_bech32();default:throw Error(`ArgumentError: unsupported address type, got ${i.AddressType[t]}`)}}static prepareAddress(t){return e.prepareXPublickey(t)}static resolveAddress(t,r,a){(0,c.default)(r,c.default.number.inRange(0,i.AddressType.__LENGTH));const n=e.resolveXPublickey(t);return e.addressConvert(n,r,a)}static prepareXPublickey(e){return(0,c.default)(e,i.ow_path),s.SecuxTransactionTool.getXPublickey(e,d.EllipticCurve.ED25519_ADA)}static resolveXPublickey(e){return s.SecuxTransactionTool.resolveXPublickey(e,void 0,d.EllipticCurve.ED25519_ADA)}static prepareSign(e,t,r){(0,c.default)(e,c.default.array.ofType(i.ow_txInput)),(0,c.default)(t,i.ow_txOutput),(0,c.default)(r,c.default.any(c.default.undefined,i.ow_signOption));const o=t.address.startsWith("DdzFF")?a.cardano.__byronConfig:a.cardano.__config,{builder:s,paths:d,publickeys:u}=_(e,o);let l;try{l=a.cardano.Address.from_bech32(t.address)}catch(e){l=a.cardano.Address.from_bytes(n.base58.decode(t.address))}s.add_output(a.cardano.TransactionOutput.new(l,a.cardano.Value.new(a.cardano.BigNum.from_str(t.amount.toString(10)))));return b(d,u,g(s,r))}static resolveSignatureList(e){return s.SecuxTransactionTool.resolveSignatureList(e).map((e=>Buffer.from(e,"base64"))).map((e=>u.Signature.fromSignature(e))).map((e=>Buffer.concat([e.r,e.s]).toString("hex")))}static resolveTransaction(t,r){(0,c.default)(r,o.ow_communicationData);const n=JSON.parse((0,o.getBuffer)(r).toString()),i=e.resolveSignatureList(t);if(i.length!==n.publickeys.length)throw Error(`expect ${n.publickeys.length} signature(s), but got ${i.length}`);const s=a.cardano.TransactionBody.from_bytes(Buffer.from(n.rawTx,"hex")),d=a.cardano.Vkeywitnesses.new();for(let e=0;e<n.publickeys.length;e++){const t=a.cardano.PublicKey.from_bytes(h(n.publickeys[e])),r=a.cardano.Ed25519Signature.from_hex(i[e]);if(!t.verify(a.cardano.hash_transaction(s).to_bytes(),r))throw null==f||f.error(`signature error, got signature ${i[e]} and publickey ${n.publickeys[e]}`),Error(`Signature error #${e}`);d.add(a.cardano.Vkeywitness.new(a.cardano.Vkey.new(t),r))}const u=a.cardano.TransactionWitnessSet.new();u.set_vkeys(d);const l=a.cardano.Transaction.new(s,u);if(!l.is_valid()){null==f||f.debug(`Cannot finalize transaction, tx: ${n.rawTx}\n`);for(let e=0;e<i.length;e++)null==f||f.debug(`signature#${e}: ${i[e]}`);throw Error("Cannot finalize transaction.")}return Buffer.from(l.to_bytes()).toString("base64")}static prepareStake(e,t,r){var n;(0,c.default)(e,i.ow_stakeInput),(0,c.default)(t,c.default.any(i.ow_poolHash,u.ow_hexString.length(56))),(0,c.default)(r,c.default.any(c.default.undefined,i.ow_stakeOption));const o=null!==(n=null==r?void 0:r.stakeIndex)&&void 0!==n?n:0,s=y(h(e.xpublickey),2,o),d=a.cardano.StakeCredential.from_keyhash(a.cardano.PublicKey.from_bytes(s).hash()),l=a.cardano.Certificates.new();(null==r?void 0:r.needRegistration)&&l.add(a.cardano.Certificate.new_stake_registration(a.cardano.StakeRegistration.new(d))),l.add(a.cardano.Certificate.new_stake_delegation(a.cardano.StakeDelegation.new(d,t.startsWith("pool")?a.cardano.Ed25519KeyHash.from_bech32(t):a.cardano.Ed25519KeyHash.from_bytes(Buffer.from(t,"hex")))));const f=e.utxo.map((t=>Object.assign({path:e.path,xpublickey:e.xpublickey},t))),{builder:p,paths:k,publickeys:w}=_(f);p.set_certs(l),k.push(`${e.path}/2/${o}`),w.push(s);return b(k,w,g(p,{fee:null==r?void 0:r.fee,TimeToLive:null==r?void 0:r.TimeToLive,changeAddress:e.changeAddress}))}static prepareUnstake(e,t){var r;(0,c.default)(e,i.ow_stakeInput),(0,c.default)(t,c.default.any(c.default.undefined,i.ow_unstakeOption));const n=null!==(r=null==t?void 0:t.stakeIndex)&&void 0!==r?r:0,o=y(h(e.xpublickey),2,n),s=a.cardano.StakeCredential.from_keyhash(a.cardano.PublicKey.from_bytes(o).hash()),d=a.cardano.Certificates.new();d.add(a.cardano.Certificate.new_stake_deregistration(a.cardano.StakeDeregistration.new(s)));const u=e.utxo.map((t=>Object.assign({path:e.path,xpublickey:e.xpublickey},t))),{builder:l,paths:f,publickeys:p}=_(u);if(l.set_certs(d),null==t?void 0:t.withdrawAmount){const e=a.cardano.Withdrawals.new();e.insert(a.cardano.RewardAddress.new(a.cardano.NetworkInfo.mainnet().network_id(),s),a.cardano.BigNum.from_str(t.withdrawAmount.toString(10))),l.set_withdrawals(e)}f.push(`${e.path}/2/${n}`),p.push(o);return b(f,p,g(l,{fee:null==t?void 0:t.fee,TimeToLive:null==t?void 0:t.TimeToLive,changeAddress:e.changeAddress}))}static prepareWithdraw(e,t,r){var n;(0,c.default)(e,i.ow_stakeInput),(0,c.default)(t,c.default.any(c.default.number.uint32.positive,u.ow_numberString)),(0,c.default)(r,c.default.any(c.default.undefined,i.ow_withdrawOption));const o=null!==(n=null==r?void 0:r.stakeIndex)&&void 0!==n?n:0,s=y(h(e.xpublickey),2,o),d=a.cardano.StakeCredential.from_keyhash(a.cardano.PublicKey.from_bytes(s).hash()),l=a.cardano.Withdrawals.new();l.insert(a.cardano.RewardAddress.new(a.cardano.NetworkInfo.mainnet().network_id(),d),a.cardano.BigNum.from_str(t.toString(10)));const f=e.utxo.map((t=>Object.assign({path:e.path,xpublickey:e.xpublickey},t))),{builder:p,paths:k,publickeys:w}=_(f);p.set_withdrawals(l),k.push(`${e.path}/2/${o}`),w.push(s);return b(k,w,g(p,{fee:null==r?void 0:r.fee,TimeToLive:null==r?void 0:r.TimeToLive,changeAddress:e.changeAddress}))}static getAddress(t,a,n){return r(this,void 0,void 0,(function*(){const r=e.prepareAddress(t),i=yield this.Exchange((0,o.getBuffer)(r));return e.resolveAddress(i,a,n)}))}static getPublickey(t,a=!0){return r(this,void 0,void 0,(function*(){(0,c.default)(t,i.ow_fullPath);const r=t.match(/\d+/g),n=e.prepareXPublickey(`m/${r[0]}'/${r[1]}'/${r[2]}'`),s=yield this.Exchange((0,o.getBuffer)(n));return y(h(e.resolveXPublickey(s)),parseInt(r[3],10),parseInt(r[4],10),a).toString("hex")}))}static getXPublickey(t){return r(this,void 0,void 0,(function*(){const r=e.prepareXPublickey(t),a=yield this.Exchange((0,o.getBuffer)(r));return e.resolveXPublickey(a)}))}static sign(...t){return r(this,void 0,void 0,(function*(){let r=e.prepareSign;if(Array.isArray(t[0])){const a={};for(const r of t[0])(0,c.default)(r.path,i.ow_path),a[r.path]||(a[r.path]=yield e.getXPublickey.call(this,r.path)),r.xpublickey=a[r.path];r=e.prepareSign}else t[0].xpublickey=yield e.getXPublickey.call(this,t[0].path),r=void 0===t[1]||"object"==typeof t[1]?e.prepareUnstake:"string"!=typeof t[1]||!t[1].startsWith("pool")&&56!==t[1].length?e.prepareWithdraw:e.prepareStake;const{commandData:a,serialized:n}=r(...t),s=yield this.Exchange((0,o.getBuffer)(a));return{raw_tx:e.resolveTransaction(s,n)}}))}};function h(e){return"string"==typeof e?Buffer.from(e,"hex"):e}function y(e,t,r,o=!0){if(o){const a=n.derivePublic(e,t,2),o=n.derivePublic(a,r,2);return Buffer.from(o.slice(0,32))}const i=a.cardano.Bip32PublicKey.from_bytes(e);return Buffer.from(i.derive(t).derive(r).as_bytes().slice(0,32))}function _(e,t){var r;const n=null!=t?t:a.cardano.__config,o=a.cardano.TransactionBuilder.new(...n),i=[],s=[];for(const t of e){const e=null!==(r=t.addressIndex)&&void 0!==r?r:0,n=y(h(t.xpublickey),0,e),d=a.cardano.TransactionInput.new(a.cardano.TransactionHash.from_bytes(Buffer.from(t.txId,"hex")),t.index),c=a.cardano.Value.new(a.cardano.BigNum.from_str(t.amount.toString(10)));o.add_key_input(a.cardano.PublicKey.from_bytes(n).hash(),d,c),i.push(`${t.path}/0/${e}`),s.push(n)}return{builder:o,paths:i,publickeys:s}}function g(e,t){t?(t.fee?e.set_fee(a.cardano.BigNum.from_str(t.fee.toString(10))):t.changeAddress&&e.add_change_if_needed(a.cardano.Address.from_bech32(t.changeAddress)),t.TimeToLive&&e.set_ttl(t.TimeToLive)):e.set_fee(e.min_fee());const r=Buffer.from(e.build().to_bytes()),n=parseInt(e.get_fee_if_set().to_str(),10),o=(i=r.length,a.cardano.__fee_a*i+a.cardano.__fee_b);var i;if(n<o)throw Error(`minimal transaction fee is ${o}, but got ${n}.`);return r}function b(e,t,r){const a=e.map((e=>r)),n=s.SecuxTransactionTool.signRawTransactionList(e,a,void 0,{tp:d.TransactionType.NORMAL,curve:d.EllipticCurve.ED25519_ADA,chainId:0}),i={rawTx:r.toString("hex"),publickeys:t.map((e=>e.toString("hex")))},c=Buffer.from(JSON.stringify(i));return{commandData:n,serialized:(0,o.toCommunicationData)(c)}}p=e=t([(0,l.staticImplements)()],p),exports.SecuxADA=p,(0,l.loadPlugin)(p,"SecuxADA");
{
"name": "@secux/app-ada",
"version": "3.0.1",
"version": "3.0.2",
"description": "SecuX Hardware Wallet ADA API",

@@ -28,3 +28,4 @@ "keywords": [

"build": "sh ../../build.sh",
"docs": "npx tsc && jsdoc2md --template ./README.hbs ./lib/app-ada.js > README.md",
"doc": "npx tsc && jsdoc2md --template ./README.hbs ./lib/app-ada.js > README.md",
"doc:api": "sh ../../api_doc.sh ./src/app-ada.ts ./lib/app-ada.js",
"test:webusb": "webpack serve --progress --config ../../webpack.config.js --output-path ./__tests__ --entry ./__tests__/usb.js",

@@ -37,7 +38,9 @@ "test:webble": "webpack serve --progress --config ../../webpack.config.js --output-path ./__tests__ --entry ./__tests__/ble.js",

"@secux/protocol-transaction": "^3.1.0",
"@secux/transport": "^3.0.1",
"@secux/utility": "^3.0.2",
"cardano-crypto.js": "^6.1.0",
"pbkdf2": "^3.1.2"
},
"peerDependencies": {
"@secux/transport": "^3.0.1"
}
}

@@ -176,36 +176,39 @@ [![lerna](https://img.shields.io/badge/maintained%20with-lerna-cc00ff.svg)](https://lerna.js.org/)

* [SecuxADA](#SecuxADA)
* [.prepareAddress](#SecuxADA.prepareAddress) ⇒ <code>communicationData</code>
* [.addressConvert(xpublickey, type, [option])](#SecuxADA.addressConvert) ⇒ <code>string</code>
* [.prepareAddress(pathWith3Depth)](#SecuxADA.prepareAddress) ⇒ [<code>communicationData</code>](#communicationData)
* [.resolveAddress(response, type, [option])](#SecuxADA.resolveAddress) ⇒ <code>string</code>
* [.prepareXPublickey(pathWith3Depth)](#SecuxADA.prepareXPublickey) ⇒ <code>communicationData</code>
* [.prepareXPublickey(pathWith3Depth)](#SecuxADA.prepareXPublickey) ⇒ [<code>communicationData</code>](#communicationData)
* [.resolveXPublickey(response)](#SecuxADA.resolveXPublickey) ⇒ <code>string</code>
* [.prepareSign(inputs, output, [option])](#SecuxADA.prepareSign) ⇒ <code>prepared</code>
* [.prepareSign(inputs, output, [option])](#SecuxADA.prepareSign) ⇒ [<code>prepared</code>](#prepared)
* [.resolveSignatureList(response)](#SecuxADA.resolveSignatureList) ⇒ <code>Array.&lt;string&gt;</code>
* [.resolveTransaction(response, serialized)](#SecuxADA.resolveTransaction) ⇒ <code>string</code>
* [.prepareStake(input, pool, [option])](#SecuxADA.prepareStake) ⇒ [<code>prepared</code>](#prepared)
* [.prepareUnstake(input, [option])](#SecuxADA.prepareUnstake) ⇒ [<code>prepared</code>](#prepared)
* [.prepareWithdraw(input, amount, [option])](#SecuxADA.prepareWithdraw) ⇒ [<code>prepared</code>](#prepared)
<br/>
<a name="SecuxADA.prepareAddress"></a>
<a name="SecuxADA.addressConvert"></a>
### **SecuxADA.prepareAddress ⇒ <code>communicationData</code>**
*Prepare data for address generation.*
### **SecuxADA.addressConvert(xpublickey, type, [option]) ⇒ <code>string</code>**
*Convert bip32-publickey to ADA address.*
**Returns**: <code>communicationData</code> - data for sending to device
**Returns**: <code>string</code> - address
| Param | Type | Description |
| --- | --- | --- |
| pathWith3Depth | <code>string</code> | m/1852'/1815'/... |
| xpublickey | <code>string</code> \| <code>Buffer</code> | ada bip32-publickey |
| type | [<code>AddressType</code>](#AddressType) | |
| [option] | [<code>AddressOption</code>](#AddressOption) | |
<br/>
<a name="SecuxADA.addressConvert"></a>
<a name="SecuxADA.prepareAddress"></a>
### **SecuxADA.addressConvert(xpublickey, type, [option]) ⇒ <code>string</code>**
*Convert bip32-publickey to ADA address.*
### **SecuxADA.prepareAddress(pathWith3Depth) ⇒ [<code>communicationData</code>](#communicationData)**
*Prepare data for address generation.*
**Returns**: <code>string</code> - address
**Returns**: [<code>communicationData</code>](#communicationData) - data for sending to device
| Param | Type | Description |
| --- | --- | --- |
| xpublickey | <code>string</code> \| <code>Buffer</code> | ada bip32-publickey |
| type | <code>AddressType</code> | |
| [option] | <code>AddressOption</code> | |
| pathWith3Depth | <code>string</code> | m/1852'/1815'/... |

@@ -222,5 +225,5 @@ <br/>

| --- | --- | --- |
| response | <code>communicationData</code> | data from device |
| type | <code>AddressType</code> | |
| [option] | <code>AddressOption</code> | |
| response | [<code>communicationData</code>](#communicationData) | data from device |
| type | [<code>AddressType</code>](#AddressType) | |
| [option] | [<code>AddressOption</code>](#AddressOption) | |

@@ -230,6 +233,6 @@ <br/>

### **SecuxADA.prepareXPublickey(pathWith3Depth) ⇒ <code>communicationData</code>**
### **SecuxADA.prepareXPublickey(pathWith3Depth) ⇒ [<code>communicationData</code>](#communicationData)**
*Prepare data for bip32-publickey.*
**Returns**: <code>communicationData</code> - data for sending to device
**Returns**: [<code>communicationData</code>](#communicationData) - data for sending to device

@@ -250,3 +253,3 @@ | Param | Type | Description |

| --- | --- | --- |
| response | <code>communicationData</code> | data from device |
| response | [<code>communicationData</code>](#communicationData) | data from device |

@@ -256,3 +259,3 @@ <br/>

### **SecuxADA.prepareSign(inputs, output, [option]) ⇒ <code>prepared</code>**
### **SecuxADA.prepareSign(inputs, output, [option]) ⇒ [<code>prepared</code>](#prepared)**
*Prepare data for signing.*

@@ -263,5 +266,5 @@

| --- | --- |
| inputs | <code>Array.&lt;txInput&gt;</code> |
| output | <code>txOutput</code> |
| [option] | <code>signOption</code> |
| inputs | [<code>Array.&lt;txInput&gt;</code>](#txInput) |
| output | [<code>txOutput</code>](#txOutput) |
| [option] | [<code>signOption</code>](#signOption) |

@@ -278,3 +281,3 @@ <br/>

| --- | --- | --- |
| response | <code>communicationData</code> | data from device |
| response | [<code>communicationData</code>](#communicationData) | data from device |

@@ -291,9 +294,202 @@ <br/>

| --- | --- | --- |
| response | <code>communicationData</code> | data from device |
| serialized | <code>communicationData</code> | |
| response | [<code>communicationData</code>](#communicationData) | data from device |
| serialized | [<code>communicationData</code>](#communicationData) | |
<br/>
<a name="SecuxADA.prepareStake"></a>
### **SecuxADA.prepareStake(input, pool, [option]) ⇒ [<code>prepared</code>](#prepared)**
*Prepare data for signing.*
| Param | Type | Description |
| --- | --- | --- |
| input | [<code>stakeInput</code>](#stakeInput) | |
| pool | <code>string</code> | pool hash or id |
| [option] | [<code>stakeOption</code>](#stakeOption) | |
<br/>
<a name="SecuxADA.prepareUnstake"></a>
### **SecuxADA.prepareUnstake(input, [option]) ⇒ [<code>prepared</code>](#prepared)**
*Prepare data for signing.*
| Param | Type |
| --- | --- |
| input | [<code>stakeInput</code>](#stakeInput) |
| [option] | [<code>unstakeOption</code>](#unstakeOption) |
<br/>
<a name="SecuxADA.prepareWithdraw"></a>
### **SecuxADA.prepareWithdraw(input, amount, [option]) ⇒ [<code>prepared</code>](#prepared)**
*Prepare data for signing.*
| Param | Type | Description |
| --- | --- | --- |
| input | [<code>stakeInput</code>](#stakeInput) | |
| amount | <code>number</code> \| <code>string</code> | rewards |
| [option] | [<code>withdrawOption</code>](#withdrawOption) | |
<br/>
<br/>
<br/>
<a name="AddressType"></a>
## AddressType : <code>enum</code>
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| BASE | <code>number</code> | 0 |
| ENTERPRISE | <code>number</code> | 1 |
| POINTER | <code>number</code> | 2 |
| REWARD | <code>number</code> | 3 |
| BOOTSTRAPv1 | <code>number</code> | 4 |
| BOOTSTRAPv2 | <code>number</code> | 5 |
<br/>
<a name="PointerOption"></a>
## PointerOption : <code>object</code>
**Properties**
| Name | Type |
| --- | --- |
| slot | <code>number</code> |
| txIndex | <code>number</code> |
| certIndex | <code>number</code> |
<br/>
<a name="AddressOption"></a>
## AddressOption : <code>object</code>
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| [addressIndex] | <code>number</code> | account index |
| [stakeIndex] | <code>number</code> | stake key index |
| [pointer] | [<code>PointerOption</code>](#PointerOption) | option for Pointer address |
<br/>
<a name="txInput"></a>
## txInput : <code>object</code>
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| path | <code>string</code> | 3-depth path of CIP-1852 |
| xpublickey | <code>string</code> \| <code>Buffer</code> | ED25519 publickey from `path` |
| txId | <code>string</code> | referenced transaction hash |
| index | <code>number</code> | referenced transaction output index |
| amount | <code>number</code> \| <code>string</code> | referenced transaction output amount |
| [addressIndex] | <code>number</code> | default: 0 |
| [stakeIndex] | <code>number</code> | default: 0 |
<br/>
<a name="txOutput"></a>
## txOutput : <code>object</code>
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| address | <code>string</code> | receiver's address |
| amount | <code>number</code> \| <code>string</code> | amount of payment |
<br/>
<a name="signOption"></a>
## signOption : <code>object</code>
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| [changeAddress] | <code>string</code> | default: sender's address |
| [fee] | <code>number</code> \| <code>string</code> | |
| [TimeToLive] | <code>number</code> | |
<br/>
<a name="stakeOption"></a>
## stakeOption : <code>object</code>
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| [stakeIndex] | <code>number</code> | default: 0 |
| [needRegistration] | <code>boolean</code> | include registration or not |
| [fee] | <code>number</code> \| <code>string</code> | |
| [TimeToLive] | <code>number</code> | |
<br/>
<a name="withdrawOption"></a>
## withdrawOption : <code>object</code>
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| [stakeIndex] | <code>number</code> | default: 0 |
| [fee] | <code>number</code> \| <code>string</code> | |
| [TimeToLive] | <code>number</code> | |
<br/>
<a name="unstakeOption"></a>
## unstakeOption : <code>object</code>
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| [stakeIndex] | <code>number</code> | default: 0 |
| [withdrawAmount] | <code>boolean</code> | withdraw and de-registration |
| [fee] | <code>number</code> \| <code>string</code> | |
| [TimeToLive] | <code>number</code> | |
<br/>
<a name="utxo"></a>
## utxo : <code>object</code>
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| txId | <code>string</code> | referenced transaction hash |
| index | <code>number</code> | referenced transaction output index |
| amount | <code>number</code> \| <code>string</code> | referenced transaction output amount |
| [addressIndex] | <code>number</code> | default: 0 |
<br/>
<a name="stakeInput"></a>
## stakeInput : <code>object</code>
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| path | <code>string</code> | 3-depth path of CIP-1852 |
| utxo | [<code>Array.&lt;utxo&gt;</code>](#utxo) | |
| changeAddress | <code>string</code> | owner's account |
| xpublickey | <code>string</code> \| <code>Buffer</code> | cardano bip32-publickey |
| [stakeIndex] | <code>number</code> | default: 0 |
<br/>
<a name="prepared"></a>
## prepared : <code>object</code>
**Properties**
| Name | Type | Description |
| --- | --- | --- |
| commandData | [<code>communicationData</code>](#communicationData) | data for sending to device |
| serialized | [<code>communicationData</code>](#communicationData) | |
<br/>
* * *

@@ -300,0 +496,0 @@

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc