@emurgo/yoroi-lib-core
Advanced tools
Comparing version 0.5.0-alpha.31 to 0.5.1-alpha.32
@@ -0,1 +1,2 @@ | ||
/// <reference types="node" /> | ||
import { BigNumber } from 'bignumber.js'; | ||
@@ -5,3 +6,3 @@ import { AccountStatePart, Addressing, AddressingAddress, CardanoAddressedUtxo, CardanoHaskellConfig, CreateDelegationTxResponse, MultiTokenValue, SendToken, Token, TxOptions, WithdrawalRequest } from './internals/models'; | ||
import * as WasmContract from './internals/wasm-contract'; | ||
import { PrivateKey, PublicKey } from './internals/wasm-contract'; | ||
import { PublicKey } from './internals/wasm-contract'; | ||
import { SignTransactionRequest as LedgerSignTransactionRequest } from '@cardano-foundation/ledgerjs-hw-app-cardano'; | ||
@@ -33,5 +34,5 @@ export { AccountService } from './account'; | ||
}, absSlotNumber: BigNumber, utxos: Array<CardanoAddressedUtxo>, withdrawalRequests: Array<WithdrawalRequest>, changeAddr: AddressingAddress, config: CardanoHaskellConfig, txOptions: TxOptions): Promise<UnsignedTx>; | ||
createUnsignedVotingTx(absSlotNumber: BigNumber, stakePrivateKey: PrivateKey, stakingKeyPath: number[], catalystPrivateKey: PrivateKey, utxos: Array<CardanoAddressedUtxo>, changeAddr: AddressingAddress, config: CardanoHaskellConfig, txOptions: TxOptions, nonce: number): Promise<UnsignedTx>; | ||
createUnsignedVotingTx(absSlotNumber: BigNumber, votingPublicKey: PublicKey, stakingKeyPath: number[], stakingPublicKey: PublicKey, utxos: Array<CardanoAddressedUtxo>, changeAddr: AddressingAddress, config: CardanoHaskellConfig, txOptions: TxOptions, nonce: number, signer: (hashedMetadata: Buffer) => Promise<string>): Promise<UnsignedTx>; | ||
createUnsignedDelegationTx(absSlotNumber: BigNumber, utxos: Array<CardanoAddressedUtxo>, stakingKey: PublicKey, registrationStatus: boolean, poolId: string | null, changeAddr: AddressingAddress, valueInAccount: MultiTokenValue, defaultToken: Token, txOptions: TxOptions, config: CardanoHaskellConfig): Promise<CreateDelegationTxResponse>; | ||
buildLedgerPayload(unsignedTx: UnsignedTx, networkId: number, byronNetworkMagic: number, addressingMap: (addr: string) => Addressing): Promise<LedgerSignTransactionRequest>; | ||
} |
@@ -25,2 +25,3 @@ "use strict"; | ||
const hash_wasm_1 = require("hash-wasm"); | ||
const bech32 = require("bech32"); | ||
const errors_1 = require("./errors"); | ||
@@ -44,2 +45,26 @@ const models_1 = require("./internals/models"); | ||
Object.defineProperty(exports, "UtxoService", { enumerable: true, get: function () { return utxo_1.UtxoService; } }); | ||
const areAddressesTheSame = (wasm, addr1, addr2) => __awaiter(void 0, void 0, void 0, function* () { | ||
const addrToHex = (addr) => __awaiter(void 0, void 0, void 0, function* () { | ||
const addrBech32 = bech32.decodeUnsafe(addr, addr.length); | ||
let hex; | ||
if (addrBech32) { | ||
hex = Buffer.from(bech32.fromWords(addrBech32.words)).toString('hex'); | ||
} | ||
else if (yield wasm.ByronAddress.isValid(addr)) { | ||
hex = Buffer.from(yield wasm.ByronAddress.fromBase58(addr) | ||
.then(b => b.toAddress()) | ||
.then(a => a.toBytes())).toString('hex'); | ||
} | ||
else if (parseInt(addr, 16).toString(16).toLocaleLowerCase() === addr.toLocaleLowerCase()) { | ||
hex = addr; | ||
} | ||
else { | ||
throw new Error('compareAddresses::addrToHex: unexpected address format - should be either hex, base58 (Byron) or bech32'); | ||
} | ||
return hex.toLowerCase(); | ||
}); | ||
const addr1Hex = yield addrToHex(addr1); | ||
const addr2Hex = yield addrToHex(addr2); | ||
return addr1Hex === addr2Hex; | ||
}); | ||
/** | ||
@@ -110,10 +135,9 @@ * Currently, the @emurgo/react-native-haskell-shelley lib defines some variables as the type `u32`, which have a max value of `4294967295`. | ||
} | ||
createUnsignedVotingTx(absSlotNumber, stakePrivateKey, stakingKeyPath, catalystPrivateKey, utxos, changeAddr, config, txOptions, nonce) { | ||
createUnsignedVotingTx(absSlotNumber, votingPublicKey, stakingKeyPath, stakingPublicKey, utxos, changeAddr, config, txOptions, nonce, signer) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const stakePublicKey = yield stakePrivateKey.toPublic(); | ||
const rewardAddress = this.Wasm.RewardAddress.new(config.networkId, yield this.Wasm.StakeCredential.fromKeyhash(yield stakePublicKey.hash())); | ||
const catalystPrivateKeyHex = Buffer.from(yield catalystPrivateKey.toPublic().then((x) => x.asBytes())).toString('hex'); | ||
const stakingPublicKeyHex = Buffer.from(yield stakePrivateKey.toPublic().then((x) => x.asBytes())).toString('hex'); | ||
const rewardAddress = this.Wasm.RewardAddress.new(config.networkId, yield this.Wasm.StakeCredential.fromKeyhash(yield stakingPublicKey.hash())); | ||
const votingPublicKeyHex = Buffer.from(yield votingPublicKey.asBytes()).toString('hex'); | ||
const stakingPublicKeyHex = Buffer.from(yield stakingPublicKey.asBytes()).toString('hex'); | ||
const registrationData = yield this.Wasm.encodeJsonStrToMetadatum(JSON.stringify({ | ||
'1': `0x${catalystPrivateKeyHex}`, | ||
'1': `0x${votingPublicKeyHex}`, | ||
'2': `0x${stakingPublicKeyHex}`, | ||
@@ -127,5 +151,3 @@ '3': `0x${rewardAddress}`, | ||
const hashedMetadata = Buffer.from(hashedMetadataStr, 'hex'); | ||
const signedHashedMetadata = yield stakePrivateKey | ||
.sign(hashedMetadata) | ||
.then((x) => x.toHex()); | ||
const signedHashedMetadata = yield signer(hashedMetadata); | ||
yield generalMetadata.insert(yield this.Wasm.BigNum.fromStr(models_1.CatalystLabels.SIG.toString()), yield this.Wasm.encodeJsonStrToMetadatum(JSON.stringify({ | ||
@@ -151,3 +173,3 @@ '1': `0x${signedHashedMetadata}` | ||
stakingKeyPath: stakingKeyPath, | ||
votingPublicKey: Buffer.from(yield stakePublicKey.asBytes()).toString('hex') | ||
votingPublicKey: Buffer.from(yield stakingPublicKey.asBytes()).toString('hex') | ||
}); | ||
@@ -254,4 +276,16 @@ return unsignedTx; | ||
} | ||
buildLedgerPayload(unsignedTx, networkId, byronNetworkMagic, addressingMap) { | ||
buildLedgerPayload(unsignedTx, networkId, byronNetworkMagic) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const addressingMap = (addr) => { | ||
var _a; | ||
const allAddresses = unsignedTx.senderUtxos.map(u => ({ | ||
address: u.receiver, | ||
addressing: u.addressing | ||
})).concat(unsignedTx.change.map(c => ({ | ||
address: c.address, | ||
addressing: c.addressing | ||
}))); | ||
const item = allAddresses.find((a) => __awaiter(this, void 0, void 0, function* () { return areAddressesTheSame(this.Wasm, a.address, addr); })); | ||
return (_a = item === null || item === void 0 ? void 0 : item.addressing) !== null && _a !== void 0 ? _a : null; | ||
}; | ||
const ledgerInputs = (0, ledger_1.transformToLedgerInputs)([...unsignedTx.senderUtxos]); | ||
@@ -258,0 +292,0 @@ const ledgerOutputs = yield (0, ledger_1.transformToLedgerOutputs)(this.Wasm, { |
{ | ||
"name": "@emurgo/yoroi-lib-core", | ||
"version": "0.5.0-alpha.31", | ||
"version": "0.5.1-alpha.32", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
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
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
284058
5044