@secux/app-ada
Advanced tools
Comparing version 3.0.2 to 3.0.3
@@ -53,3 +53,3 @@ /// <reference types="node" /> | ||
commandData: communicationData; | ||
serialized: string | Buffer; | ||
serialized: communicationData; | ||
}; | ||
@@ -78,3 +78,3 @@ /** | ||
commandData: communicationData; | ||
serialized: string | Buffer; | ||
serialized: communicationData; | ||
}; | ||
@@ -89,3 +89,3 @@ /** | ||
commandData: communicationData; | ||
serialized: string | Buffer; | ||
serialized: communicationData; | ||
}; | ||
@@ -101,3 +101,3 @@ /** | ||
commandData: communicationData; | ||
serialized: string | Buffer; | ||
serialized: communicationData; | ||
}; | ||
@@ -104,0 +104,0 @@ static getAddress(this: ITransport, pathWith3Depth: string, type: AddressType, option?: AddressOption): Promise<string>; |
@@ -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 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"); | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.AddressType=exports.SecuxADA=void 0;const e=require("./load_lib"),a=require("cardano-crypto.js"),t=require("@secux/utility/lib/communication"),r=require("./interface");Object.defineProperty(exports,"AddressType",{enumerable:!0,get:function(){return r.AddressType}});const n=require("@secux/protocol-transaction"),o=require("@secux/protocol-transaction/lib/interface"),s=require("ow"),i=require("@secux/utility"),d=null===i.Logger||void 0===i.Logger?void 0:i.Logger.child({id:"ada"});class c{static addressConvert(t,n,o){var i,d,c;(0,s.default)(t,r.ow_xpublickey),(0,s.default)(n,s.default.number.inRange(0,r.AddressType.__LENGTH-1)),(0,s.default)(o,s.default.any(s.default.undefined,r.ow_AddressOption));const l=u(t),f=e.cardano.Bip32PublicKey.from_bytes(l),p=f.derive(0).derive(null!==(i=null==o?void 0:o.addressIndex)&&void 0!==i?i:0),h=f.derive(2).derive(null!==(d=null==o?void 0:o.stakeIndex)&&void 0!==d?d:0);switch(n){case r.AddressType.BOOTSTRAPv1:const{pbkdf2Sync:t}=require("pbkdf2"),i=t(l,"address-hashing",500,32,"sha512");return a.base58.encode(a.packBootstrapAddress([2147483648,2147483648|(null!==(c=null==o?void 0:o.addressIndex)&&void 0!==c?c:0)],l,i,1,e.cardano.NetworkInfo.mainnet().protocol_magic()));case r.AddressType.BOOTSTRAPv2:return e.cardano.ByronAddress.icarus_from_key(p,e.cardano.NetworkInfo.mainnet().protocol_magic()).to_base58();case r.AddressType.BASE:return e.cardano.BaseAddress.new(e.cardano.NetworkInfo.mainnet().network_id(),e.cardano.StakeCredential.from_keyhash(p.to_raw_key().hash()),e.cardano.StakeCredential.from_keyhash(h.to_raw_key().hash())).to_address().to_bech32();case r.AddressType.ENTERPRISE:return e.cardano.EnterpriseAddress.new(e.cardano.NetworkInfo.mainnet().network_id(),e.cardano.StakeCredential.from_keyhash(p.to_raw_key().hash())).to_address().to_bech32();case r.AddressType.POINTER:const d=o.pointer;return(0,s.default)(d,r.ow_PointerOption),e.cardano.PointerAddress.new(e.cardano.NetworkInfo.mainnet().network_id(),e.cardano.StakeCredential.from_keyhash(p.to_raw_key().hash()),e.cardano.Pointer.new(d.slot,d.txIndex,d.certIndex)).to_address().to_bech32();case r.AddressType.REWARD:return e.cardano.RewardAddress.new(e.cardano.NetworkInfo.mainnet().network_id(),e.cardano.StakeCredential.from_keyhash(h.to_raw_key().hash())).to_address().to_bech32();default:throw Error(`ArgumentError: unsupported address type, got ${r.AddressType[n]}`)}}static prepareAddress(e){return c.prepareXPublickey(e)}static resolveAddress(e,a,t){(0,s.default)(a,s.default.number.inRange(0,r.AddressType.__LENGTH));const n=c.resolveXPublickey(e);return c.addressConvert(n,a,t)}static prepareXPublickey(e){return(0,s.default)(e,r.ow_path),n.SecuxTransactionTool.getXPublickey(e,o.EllipticCurve.ED25519_ADA)}static resolveXPublickey(e){return n.SecuxTransactionTool.resolveXPublickey(e,void 0,o.EllipticCurve.ED25519_ADA)}static prepareSign(t,n,o){(0,s.default)(t,s.default.array.ofType(r.ow_txInput)),(0,s.default)(n,r.ow_txOutput),(0,s.default)(o,s.default.any(s.default.undefined,r.ow_signOption));const i=n.address.startsWith("DdzFF")?e.cardano.__byronConfig:e.cardano.__config,{builder:d,paths:c,publickeys:u}=f(t,i);let l;try{l=e.cardano.Address.from_bech32(n.address)}catch(t){l=e.cardano.Address.from_bytes(a.base58.decode(n.address))}d.add_output(e.cardano.TransactionOutput.new(l,e.cardano.Value.new(e.cardano.BigNum.from_str(n.amount.toString(10)))));return h(c,u,p(d,o))}static resolveSignatureList(e){return n.SecuxTransactionTool.resolveSignatureList(e).map((e=>Buffer.from(e,"base64"))).map((e=>i.Signature.fromSignature(e))).map((e=>Buffer.concat([e.r,e.s]).toString("hex")))}static resolveTransaction(a,r){(0,s.default)(r,t.ow_communicationData);const n=JSON.parse((0,t.getBuffer)(r).toString()),o=c.resolveSignatureList(a);if(o.length!==n.publickeys.length)throw Error(`expect ${n.publickeys.length} signature(s), but got ${o.length}`);const i=e.cardano.TransactionBody.from_bytes(Buffer.from(n.rawTx,"hex")),l=e.cardano.Vkeywitnesses.new();for(let a=0;a<n.publickeys.length;a++){const t=e.cardano.PublicKey.from_bytes(u(n.publickeys[a])),r=e.cardano.Ed25519Signature.from_hex(o[a]);if(!t.verify(e.cardano.hash_transaction(i).to_bytes(),r))throw null==d||d.error(`signature error, got signature ${o[a]} and publickey ${n.publickeys[a]}`),Error(`Signature error #${a}`);l.add(e.cardano.Vkeywitness.new(e.cardano.Vkey.new(t),r))}const f=e.cardano.TransactionWitnessSet.new();f.set_vkeys(l);const p=e.cardano.Transaction.new(i,f);if(!p.is_valid()){null==d||d.debug(`Cannot finalize transaction, tx: ${n.rawTx}\n`);for(let e=0;e<o.length;e++)null==d||d.debug(`signature#${e}: ${o[e]}`);throw Error("Cannot finalize transaction.")}return Buffer.from(p.to_bytes()).toString("base64")}static prepareStake(a,t,n){var o;(0,s.default)(a,r.ow_stakeInput),(0,s.default)(t,s.default.any(r.ow_poolHash,i.owTool.hexString.length(56))),(0,s.default)(n,s.default.any(s.default.undefined,r.ow_stakeOption));const d=null!==(o=null==n?void 0:n.stakeIndex)&&void 0!==o?o:0,c=l(u(a.xpublickey),2,d),_=e.cardano.StakeCredential.from_keyhash(e.cardano.PublicKey.from_bytes(c).hash()),y=e.cardano.Certificates.new();(null==n?void 0:n.needRegistration)&&y.add(e.cardano.Certificate.new_stake_registration(e.cardano.StakeRegistration.new(_))),y.add(e.cardano.Certificate.new_stake_delegation(e.cardano.StakeDelegation.new(_,t.startsWith("pool")?e.cardano.Ed25519KeyHash.from_bech32(t):e.cardano.Ed25519KeyHash.from_bytes(Buffer.from(t,"hex")))));const g=a.utxo.map((e=>Object.assign({path:a.path,xpublickey:a.xpublickey},e))),{builder:b,paths:w,publickeys:k}=f(g);b.set_certs(y),w.push(`${a.path}/2/${d}`),k.push(c);return h(w,k,p(b,{fee:null==n?void 0:n.fee,TimeToLive:null==n?void 0:n.TimeToLive,changeAddress:a.changeAddress}))}static prepareUnstake(a,t){var n;(0,s.default)(a,r.ow_stakeInput),(0,s.default)(t,s.default.any(s.default.undefined,r.ow_unstakeOption));const o=null!==(n=null==t?void 0:t.stakeIndex)&&void 0!==n?n:0,i=l(u(a.xpublickey),2,o),d=e.cardano.StakeCredential.from_keyhash(e.cardano.PublicKey.from_bytes(i).hash()),c=e.cardano.Certificates.new();c.add(e.cardano.Certificate.new_stake_deregistration(e.cardano.StakeDeregistration.new(d)));const _=a.utxo.map((e=>Object.assign({path:a.path,xpublickey:a.xpublickey},e))),{builder:y,paths:g,publickeys:b}=f(_);if(y.set_certs(c),null==t?void 0:t.withdrawAmount){const a=e.cardano.Withdrawals.new();a.insert(e.cardano.RewardAddress.new(e.cardano.NetworkInfo.mainnet().network_id(),d),e.cardano.BigNum.from_str(t.withdrawAmount.toString(10))),y.set_withdrawals(a)}g.push(`${a.path}/2/${o}`),b.push(i);return h(g,b,p(y,{fee:null==t?void 0:t.fee,TimeToLive:null==t?void 0:t.TimeToLive,changeAddress:a.changeAddress}))}static prepareWithdraw(a,t,n){var o;(0,s.default)(a,r.ow_stakeInput),(0,s.default)(t,s.default.any(s.default.number.uint32.positive,i.owTool.numberString)),(0,s.default)(n,s.default.any(s.default.undefined,r.ow_withdrawOption));const d=null!==(o=null==n?void 0:n.stakeIndex)&&void 0!==o?o:0,c=l(u(a.xpublickey),2,d),_=e.cardano.StakeCredential.from_keyhash(e.cardano.PublicKey.from_bytes(c).hash()),y=e.cardano.Withdrawals.new();y.insert(e.cardano.RewardAddress.new(e.cardano.NetworkInfo.mainnet().network_id(),_),e.cardano.BigNum.from_str(t.toString(10)));const g=a.utxo.map((e=>Object.assign({path:a.path,xpublickey:a.xpublickey},e))),{builder:b,paths:w,publickeys:k}=f(g);b.set_withdrawals(y),w.push(`${a.path}/2/${d}`),k.push(c);return h(w,k,p(b,{fee:null==n?void 0:n.fee,TimeToLive:null==n?void 0:n.TimeToLive,changeAddress:a.changeAddress}))}static async getAddress(e,a,r){const n=c.prepareAddress(e),o=await this.Exchange((0,t.getBuffer)(n));return c.resolveAddress(o,a,r)}static async getPublickey(e,a=!0){(0,s.default)(e,r.ow_fullPath);const n=e.match(/\d+/g),o=c.prepareXPublickey(`m/${n[0]}'/${n[1]}'/${n[2]}'`),i=await this.Exchange((0,t.getBuffer)(o));return l(u(c.resolveXPublickey(i)),parseInt(n[3],10),parseInt(n[4],10),a).toString("hex")}static async getXPublickey(e){const a=c.prepareXPublickey(e),r=await this.Exchange((0,t.getBuffer)(a));return c.resolveXPublickey(r)}static async sign(...e){let a=c.prepareSign;if(Array.isArray(e[0])){const t={};for(const a of e[0])(0,s.default)(a.path,r.ow_path),t[a.path]||(t[a.path]=await c.getXPublickey.call(this,a.path)),a.xpublickey=t[a.path];a=c.prepareSign}else e[0].xpublickey=await c.getXPublickey.call(this,e[0].path),a=void 0===e[1]||"object"==typeof e[1]?c.prepareUnstake:"string"!=typeof e[1]||!e[1].startsWith("pool")&&56!==e[1].length?c.prepareWithdraw:c.prepareStake;const{commandData:n,serialized:o}=a(...e),i=await this.Exchange((0,t.getBuffer)(n));return{raw_tx:c.resolveTransaction(i,o)}}}function u(e){return"string"==typeof e?Buffer.from(e,"hex"):e}function l(t,r,n,o=!0){if(o){const e=a.derivePublic(t,r,2),o=a.derivePublic(e,n,2);return Buffer.from(o.slice(0,32))}const s=e.cardano.Bip32PublicKey.from_bytes(t);return Buffer.from(s.derive(r).derive(n).as_bytes().slice(0,32))}function f(a,t){var r;const n=null!=t?t:e.cardano.__config,o=e.cardano.TransactionBuilder.new(...n),s=[],i=[];for(const t of a){const a=null!==(r=t.addressIndex)&&void 0!==r?r:0,n=l(u(t.xpublickey),0,a),d=e.cardano.TransactionInput.new(e.cardano.TransactionHash.from_bytes(Buffer.from(t.txId,"hex")),t.index),c=e.cardano.Value.new(e.cardano.BigNum.from_str(t.amount.toString(10)));o.add_key_input(e.cardano.PublicKey.from_bytes(n).hash(),d,c),s.push(`${t.path}/0/${a}`),i.push(n)}return{builder:o,paths:s,publickeys:i}}function p(a,t){t?(t.fee?a.set_fee(e.cardano.BigNum.from_str(t.fee.toString(10))):t.changeAddress&&a.add_change_if_needed(e.cardano.Address.from_bech32(t.changeAddress)),t.TimeToLive&&a.set_ttl(t.TimeToLive)):a.set_fee(a.min_fee());const r=Buffer.from(a.build().to_bytes()),n=parseInt(a.get_fee_if_set().to_str(),10),o=(s=r.length,e.cardano.__fee_a*s+e.cardano.__fee_b);var s;if(n<o)throw Error(`minimal transaction fee is ${o}, but got ${n}.`);return r}function h(e,a,r){const s=e.map((e=>r)),i=n.SecuxTransactionTool.signRawTransactionList(e,s,void 0,{tp:o.TransactionType.NORMAL,curve:o.EllipticCurve.ED25519_ADA,chainId:0}),d={rawTx:r.toString("hex"),publickeys:a.map((e=>e.toString("hex")))},c=Buffer.from(JSON.stringify(d));return(0,t.wrapResult)({commandData:i,serialized:(0,t.toCommunicationData)(c)})}exports.SecuxADA=c,(0,i.loadPlugin)(c,"SecuxADA"); |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ow_withdrawOption=exports.ow_unstakeOption=exports.ow_stakeOption=exports.ow_signOption=exports.ow_stakeInput=exports.ow_txOutput=exports.ow_txInput=exports.ow_AddressOption=exports.ow_PointerOption=exports.AddressType=exports.ow_PublickeyOption=exports.ow_poolHash=exports.ow_shelleyAddress=exports.ow_address=exports.ow_fullPath=exports.ow_path=exports.ow_xpublickey=void 0;const e=require("@secux/utility"),t=require("./utils"),o=require("ow");exports.ow_xpublickey=o.default.any(o.default.string.matches(/^[0-9A-F-a-f]{128}$/),(0,e.ow_checkBufferLength)(64)),exports.ow_path=o.default.string.matches(/^m\/1852'\/1815'\/\d+'$/),exports.ow_fullPath=(0,e.ow_strictPath)(1815,1852),exports.ow_address=o.default.string.is((e=>!!(0,t.isAddress)(e)||`ArgumentError: unsupported address, got ${e}`)),exports.ow_shelleyAddress=o.default.string.is((e=>!!(0,t.isShelleyAddress)(e)||`ArgumentError: support shelley address only, but got ${e}`)),exports.ow_poolHash=o.default.string.is((e=>!!(0,t.isPool)(e)||`ArgumentError: invalid pool hash, got ${e}`));const s=o.default.string.matches(/^[0-9A-Fa-f]{64}$/),a=o.default.number.uint8,r=o.default.any(o.default.number.uint32.positive,e.ow_numberString),d=o.default.optional.number.uint8,n=o.default.optional.number.uint8;exports.ow_PublickeyOption=o.default.object.exactShape({change:o.default.number.uint8,addressIndex:d}),function(e){e[e.BASE=0]="BASE",e[e.ENTERPRISE=1]="ENTERPRISE",e[e.POINTER=2]="POINTER",e[e.REWARD=3]="REWARD",e[e.BOOTSTRAPv1=4]="BOOTSTRAPv1",e[e.BOOTSTRAPv2=5]="BOOTSTRAPv2",e[e.__LENGTH=6]="__LENGTH"}(exports.AddressType||(exports.AddressType={})),exports.ow_PointerOption=o.default.object.exactShape({slot:o.default.number.uint32,txIndex:o.default.number.uint32,certIndex:o.default.number.uint32}),exports.ow_AddressOption=o.default.object.partialShape({addressIndex:d,stakeIndex:n}),exports.ow_txInput=o.default.object.exactShape({path:exports.ow_path,txId:s,index:a,amount:r,xpublickey:exports.ow_xpublickey,addressIndex:d,stakeIndex:n}),exports.ow_txOutput=o.default.object.exactShape({address:exports.ow_address,amount:r}),exports.ow_stakeInput=o.default.object.exactShape({path:exports.ow_path,utxo:o.default.array.ofType(o.default.object.exactShape({txId:s,index:a,amount:r,addressIndex:d})),changeAddress:exports.ow_shelleyAddress,xpublickey:exports.ow_xpublickey,stakeIndex:n});const u={fee:o.default.any(o.default.undefined,o.default.number.uint32.positive,e.ow_numberString),TimeToLive:o.default.optional.number.uint32.positive};exports.ow_signOption=o.default.object.exactShape(Object.assign({changeAddress:o.default.any(o.default.undefined,exports.ow_shelleyAddress)},u)),exports.ow_stakeOption=o.default.object.exactShape(Object.assign({stakeIndex:n,needRegistration:o.default.optional.boolean},u)),exports.ow_unstakeOption=o.default.object.exactShape(Object.assign({stakeIndex:n,withdrawAmount:o.default.any(o.default.undefined,o.default.number.uint32.positive,e.ow_numberString)},u)),exports.ow_withdrawOption=o.default.object.exactShape(Object.assign({stakeIndex:n},u)); | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ow_withdrawOption=exports.ow_unstakeOption=exports.ow_stakeOption=exports.ow_signOption=exports.ow_stakeInput=exports.ow_txOutput=exports.ow_txInput=exports.ow_AddressOption=exports.ow_PointerOption=exports.AddressType=exports.ow_PublickeyOption=exports.ow_poolHash=exports.ow_shelleyAddress=exports.ow_address=exports.ow_fullPath=exports.ow_path=exports.ow_xpublickey=void 0;const e=require("@secux/utility"),t=require("./utils"),o=require("ow");exports.ow_xpublickey=o.default.any(o.default.string.matches(/^[0-9A-F-a-f]{128}$/),(0,e.ow_checkBufferLength)(64)),exports.ow_path=o.default.string.matches(/^m\/1852'\/1815'\/\d+'$/),exports.ow_fullPath=(0,e.ow_strictPath)(1815,1852),exports.ow_address=o.default.string.is((e=>!!(0,t.isAddress)(e)||`ArgumentError: unsupported address, got ${e}`)),exports.ow_shelleyAddress=o.default.string.is((e=>!!(0,t.isShelleyAddress)(e)||`ArgumentError: support shelley address only, but got ${e}`)),exports.ow_poolHash=o.default.string.is((e=>!!(0,t.isPool)(e)||`ArgumentError: invalid pool hash, got ${e}`));const s=o.default.string.matches(/^[0-9A-Fa-f]{64}$/),a=o.default.number.uint8,r=o.default.any(o.default.number.uint32.positive,e.owTool.numberString),d=o.default.optional.number.uint8,n=o.default.optional.number.uint8;exports.ow_PublickeyOption=o.default.object.exactShape({change:o.default.number.uint8,addressIndex:d}),function(e){e[e.BASE=0]="BASE",e[e.ENTERPRISE=1]="ENTERPRISE",e[e.POINTER=2]="POINTER",e[e.REWARD=3]="REWARD",e[e.BOOTSTRAPv1=4]="BOOTSTRAPv1",e[e.BOOTSTRAPv2=5]="BOOTSTRAPv2",e[e.__LENGTH=6]="__LENGTH"}(exports.AddressType||(exports.AddressType={})),exports.ow_PointerOption=o.default.object.exactShape({slot:o.default.number.uint32,txIndex:o.default.number.uint32,certIndex:o.default.number.uint32}),exports.ow_AddressOption=o.default.object.partialShape({addressIndex:d,stakeIndex:n}),exports.ow_txInput=o.default.object.exactShape({path:exports.ow_path,txId:s,index:a,amount:r,xpublickey:exports.ow_xpublickey,addressIndex:d,stakeIndex:n}),exports.ow_txOutput=o.default.object.exactShape({address:exports.ow_address,amount:r}),exports.ow_stakeInput=o.default.object.exactShape({path:exports.ow_path,utxo:o.default.array.ofType(o.default.object.exactShape({txId:s,index:a,amount:r,addressIndex:d})),changeAddress:exports.ow_shelleyAddress,xpublickey:exports.ow_xpublickey,stakeIndex:n});const u={fee:o.default.any(o.default.undefined,o.default.number.uint32.positive,e.owTool.numberString),TimeToLive:o.default.optional.number.uint32.positive};exports.ow_signOption=o.default.object.exactShape(Object.assign({changeAddress:o.default.any(o.default.undefined,exports.ow_shelleyAddress)},u)),exports.ow_stakeOption=o.default.object.exactShape(Object.assign({stakeIndex:n,needRegistration:o.default.optional.boolean},u)),exports.ow_unstakeOption=o.default.object.exactShape(Object.assign({stakeIndex:n,withdrawAmount:o.default.any(o.default.undefined,o.default.number.uint32.positive,e.owTool.numberString)},u)),exports.ow_withdrawOption=o.default.object.exactShape(Object.assign({stakeIndex:n},u)); |
@@ -1,1 +0,1 @@ | ||
"use strict";var e=this&&this.__awaiter||function(e,r,t,o){return new(t||(t=Promise))((function(i,n){function f(e){try{_(o.next(e))}catch(e){n(e)}}function c(e){try{_(o.throw(e))}catch(e){n(e)}}function _(e){var r;e.done?i(e.value):(r=e.value,r instanceof t?r:new t((function(e){e(r)}))).then(f,c)}_((o=o.apply(e,r||[])).next())}))};let r;Object.defineProperty(exports,"__esModule",{value:!0}),exports.cardano=void 0,exports.cardano=r,e(void 0,void 0,void 0,(function*(){exports.cardano=r=yield Promise.resolve().then((()=>require("@emurgo/cardano-serialization-lib-asmjs"))),r.__fee_a=44,r.__fee_b=155381,r.__config=[Object.freeze(r.LinearFee.new(r.BigNum.from_str(r.__fee_a.toString(10)),r.BigNum.from_str(r.__fee_b.toString(10)))),Object.freeze(r.BigNum.from_str("0")),Object.freeze(r.BigNum.from_str("500000000")),Object.freeze(r.BigNum.from_str("2000000")),Object.freeze(5e3),Object.freeze(16384)],r.__byronConfig=[Object.freeze(r.LinearFee.new(r.BigNum.from_str("67"),r.BigNum.from_str("155381"))),Object.freeze(r.BigNum.from_str("0")),Object.freeze(r.BigNum.from_str("500000000")),Object.freeze(r.BigNum.from_str("2000000")),Object.freeze(5e3),Object.freeze(16384)],exports.cardano=r=Object.freeze(r)})); | ||
"use strict";let e;Object.defineProperty(exports,"__esModule",{value:!0}),exports.cardano=void 0,exports.cardano=e,(async()=>{exports.cardano=e=await Promise.resolve().then((()=>require("@emurgo/cardano-serialization-lib-asmjs"))),e.__fee_a=44,e.__fee_b=155381,e.__config=[Object.freeze(e.LinearFee.new(e.BigNum.from_str(e.__fee_a.toString(10)),e.BigNum.from_str(e.__fee_b.toString(10)))),Object.freeze(e.BigNum.from_str("0")),Object.freeze(e.BigNum.from_str("500000000")),Object.freeze(e.BigNum.from_str("2000000")),Object.freeze(5e3),Object.freeze(16384)],e.__byronConfig=[Object.freeze(e.LinearFee.new(e.BigNum.from_str("67"),e.BigNum.from_str("155381"))),Object.freeze(e.BigNum.from_str("0")),Object.freeze(e.BigNum.from_str("500000000")),Object.freeze(e.BigNum.from_str("2000000")),Object.freeze(5e3),Object.freeze(16384)],exports.cardano=e=Object.freeze(e)})(); |
{ | ||
"name": "@secux/app-ada", | ||
"version": "3.0.2", | ||
"version": "3.0.3", | ||
"description": "SecuX Hardware Wallet ADA API", | ||
@@ -21,3 +21,4 @@ "keywords": [ | ||
"files": [ | ||
"lib" | ||
"lib", | ||
"dist" | ||
], | ||
@@ -38,3 +39,3 @@ "publishConfig": { | ||
"@secux/protocol-transaction": "^3.1.0", | ||
"@secux/utility": "^3.0.2", | ||
"@secux/utility": "^3.0.6", | ||
"cardano-crypto.js": "^6.1.0", | ||
@@ -44,4 +45,4 @@ "pbkdf2": "^3.1.2" | ||
"peerDependencies": { | ||
"@secux/transport": "^3.0.1" | ||
"@secux/transport": "^3.2.0" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4923542
13
1351
1
Updated@secux/utility@^3.0.6