@emurgo/yoroi-lib
Advanced tools
Comparing version 0.11.0 to 0.13.0
import { BigNumber } from 'bignumber.js'; | ||
import { AccountStatePart, AddressingAddress, AmountWithReceiver, CardanoAddressedUtxo, CardanoHaskellConfig, Datum, MultiTokenValue, RegistrationStatus, SendToken, StakingKeyBalances, Token, TxOptions, WithdrawalRequest } from './internals/models'; | ||
import { AccountStatePart, Addressing, AddressingAddress, AmountWithReceiver, CardanoAddressedUtxo, CardanoHaskellConfig, Datum, MultiTokenValue, RegistrationStatus, SendToken, StakingKeyBalances, Token, TxOptions, WithdrawalRequest } from './internals/models'; | ||
import { UnsignedTx } from './internals/tx'; | ||
import * as WasmContract from '@emurgo/cross-csl-core'; | ||
import { PublicKey } from '@emurgo/cross-csl-core'; | ||
import { BigNum, Ed25519KeyHash, PublicKey } from '@emurgo/cross-csl-core'; | ||
import { SignTransactionRequest as LedgerSignTransactionRequest, SignTransactionResponse as LedgerSignTransactionResponse } from '@cardano-foundation/ledgerjs-hw-app-cardano'; | ||
@@ -12,2 +12,3 @@ export { AccountService } from './account'; | ||
export * from './internals/plutus'; | ||
export * from './CIP30'; | ||
export { init as initUtxo, UtxoService, UtxoStorage } from './utxo'; | ||
@@ -50,1 +51,8 @@ export * as UtxoModels from './utxo/models'; | ||
} | ||
export declare const getTxBuilder: (wasmV4: WasmContract.WasmModuleProxy, linearFee: WasmContract.LinearFee, poolDeposit: WasmContract.BigNum, keyDeposit: WasmContract.BigNum, coinsPerUtxoWord: WasmContract.BigNum) => Promise<WasmContract.TransactionBuilder>; | ||
export declare const createSignedLedgerTxFromCbor: (wasm: WasmContract.WasmModuleProxy, cbor: string, witnesses: Array<{ | ||
path: number[]; | ||
witnessSignatureHex: string; | ||
}>, purpose: number, publicKeyHex: string) => Promise<Uint8Array>; | ||
export declare const getAllSigners: (wasm: WasmContract.WasmModuleProxy, body: WasmContract.TransactionBody, networkId: number, stakeVKHash: WasmContract.Ed25519KeyHash, getAddressAddressing: (address: string) => Addressing | null, utxos: Array<CardanoAddressedUtxo>) => Promise<Addressing[]>; | ||
export declare const signRawTransaction: (wasm: WasmContract.WasmModuleProxy, cbor: string, pKeys: WasmContract.PrivateKey[]) => Promise<Uint8Array>; |
@@ -41,3 +41,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createYoroiLib = exports.RUST_u32_MAX = exports.UtxoModels = exports.UtxoService = exports.initUtxo = exports.AccountService = void 0; | ||
exports.signRawTransaction = exports.getAllSigners = exports.createSignedLedgerTxFromCbor = exports.getTxBuilder = exports.createYoroiLib = exports.RUST_u32_MAX = exports.UtxoModels = exports.UtxoService = exports.initUtxo = exports.AccountService = void 0; | ||
const bignumber_js_1 = require("bignumber.js"); | ||
@@ -60,2 +60,3 @@ const blake2b_1 = __importDefault(require("./internals/blake2b")); | ||
__exportStar(require("./internals/plutus"), exports); | ||
__exportStar(require("./CIP30"), exports); | ||
var utxo_1 = require("./utxo"); | ||
@@ -229,3 +230,3 @@ Object.defineProperty(exports, "initUtxo", { enumerable: true, get: function () { return utxo_1.init; } }); | ||
neededHashes: new Set([ | ||
Buffer.from(yield this.Wasm.StakeCredential.fromKeyhash(yield stakingKey.hash()).then(x => x.toBytes())).toString('hex') | ||
Buffer.from(yield this.Wasm.Credential.fromKeyhash(yield stakingKey.hash()).then(x => x.toBytes())).toString('hex') | ||
]), | ||
@@ -600,3 +601,3 @@ wits: new Set() | ||
} | ||
const txBuilder = yield getTxBuilder(this.Wasm, protocolParams.linearFee, protocolParams.poolDeposit, protocolParams.keyDeposit, protocolParams.coinsPerUtxoWord); | ||
const txBuilder = yield (0, exports.getTxBuilder)(this.Wasm, protocolParams.linearFee, protocolParams.poolDeposit, protocolParams.keyDeposit, protocolParams.coinsPerUtxoWord); | ||
yield txBuilder.setTtl(absSlotNumber.plus(defaultTtlOffset).toNumber()); | ||
@@ -788,3 +789,3 @@ for (const input of allUtxos) { | ||
yield shouldForceChange(undefined); | ||
const txBuilder = yield getTxBuilder(this.Wasm, protocolParams.linearFee, protocolParams.poolDeposit, protocolParams.keyDeposit, protocolParams.coinsPerUtxoWord); | ||
const txBuilder = yield (0, exports.getTxBuilder)(this.Wasm, protocolParams.linearFee, protocolParams.poolDeposit, protocolParams.keyDeposit, protocolParams.coinsPerUtxoWord); | ||
if (certificates.length > 0) { | ||
@@ -1011,1 +1012,109 @@ const certsWasm = yield this.Wasm.Certificates.new(); | ||
}); | ||
exports.getTxBuilder = getTxBuilder; | ||
const createSignedLedgerTxFromCbor = (wasm, cbor, witnesses, purpose, publicKeyHex) => __awaiter(void 0, void 0, void 0, function* () { | ||
const fixedTx = yield wasm.FixedTransaction.fromHex(cbor); | ||
if (!fixedTx) | ||
throw new Error('invalid tx hex'); | ||
const witSet = yield fixedTx.witnessSet(); | ||
const vkeys = yield wasm.Vkeywitnesses.new(); | ||
const addressing = { | ||
path: [ | ||
purpose, | ||
2147485463, | ||
2147483648, | ||
], | ||
startLevel: 1, | ||
}; | ||
const key = yield wasm.Bip32PublicKey.fromBytes(Buffer.from(publicKeyHex, 'hex')); | ||
const keyLevel = addressing.startLevel + addressing.path.length - 1; | ||
for (let i = 0; i < witnesses.length; i++) { | ||
const addressKey = yield (0, addresses_1.derivePublicByAddressing)({ startLevel: 1, path: witnesses[i].path }, { level: keyLevel, key }); | ||
const witness = yield wasm.Vkeywitness.new(yield wasm.Vkey.new(yield addressKey.toRawKey()), yield wasm.Ed25519Signature.fromBytes(Buffer.from(witnesses[i].witnessSignatureHex, 'hex'))); | ||
if (!witness) | ||
throw new Error('invalid tx hex, could not generate vkey witness'); | ||
yield vkeys.add(witness); | ||
} | ||
yield witSet.setVkeys(vkeys); | ||
yield fixedTx.setWitnessSet(yield witSet.toBytes()); | ||
return fixedTx.toBytes(); | ||
}); | ||
exports.createSignedLedgerTxFromCbor = createSignedLedgerTxFromCbor; | ||
const getAllSigners = (wasm, body, networkId, stakeVKHash, getAddressAddressing, utxos) => __awaiter(void 0, void 0, void 0, function* () { | ||
const requiredSignersAddressing = yield getRequiredSignersAddressing(wasm, body, networkId, stakeVKHash, getAddressAddressing); | ||
const inputsAddressing = yield getInputsAddressing(wasm, body, utxos); | ||
const collateralAddressing = yield getCollateralAddressing(wasm, body, utxos); | ||
return [...requiredSignersAddressing, ...inputsAddressing, ...collateralAddressing]; | ||
}); | ||
exports.getAllSigners = getAllSigners; | ||
const getInputsAddressing = (wasm, body, utxos) => __awaiter(void 0, void 0, void 0, function* () { | ||
const inputs = yield body.inputs(); | ||
const inputUtxos = []; | ||
for (let i = 0; i < (yield inputs.len()); i++) { | ||
const input = yield inputs.get(i); | ||
const txId = yield input.transactionId().then((t) => t.toHex()); | ||
const txIndex = yield input.index(); | ||
const matchingUtxo = utxos.find((utxo) => utxo.txHash === txId && utxo.txIndex === txIndex); | ||
if (!matchingUtxo) | ||
continue; | ||
inputUtxos.push(matchingUtxo); | ||
} | ||
return inputUtxos.map(u => u.addressing); | ||
}); | ||
const getCollateralAddressing = (wasm, body, utxos) => __awaiter(void 0, void 0, void 0, function* () { | ||
const collateral = yield body.collateral(); | ||
if (!collateral) | ||
return []; | ||
const collateralUtxos = []; | ||
for (let i = 0; i < (yield collateral.len()); i++) { | ||
const input = yield collateral.get(i); | ||
const txId = yield input.transactionId().then((t) => t.toHex()); | ||
const txIndex = yield input.index(); | ||
const matchingUtxo = utxos.find((utxo) => utxo.txHash === txId && utxo.txIndex === txIndex); | ||
if (!matchingUtxo) | ||
continue; | ||
collateralUtxos.push(matchingUtxo); | ||
} | ||
return collateralUtxos.map(u => u.addressing); | ||
}); | ||
const getRequiredSignersAddressing = (wasm, body, networkId, stakeVKHash, getAddressAddressing) => __awaiter(void 0, void 0, void 0, function* () { | ||
const originalRequiredSigners = yield getRequiredSigners(body); | ||
return yield Promise.all(originalRequiredSigners.map((s) => __awaiter(void 0, void 0, void 0, function* () { | ||
const paymentStakeCredential = yield wasm.Credential.fromKeyhash(s); | ||
const stakeCredential = yield wasm.Credential.fromKeyhash(stakeVKHash); | ||
const baseAddress = yield wasm.BaseAddress.new(networkId, paymentStakeCredential, stakeCredential); | ||
const addressing = getAddressAddressing(yield baseAddress.toAddress().then(a => a.toBech32())); | ||
if (!addressing) | ||
throw new Error(`Could not find addressing for required signer: ${yield s.toHex()}`); | ||
return addressing; | ||
}))); | ||
}); | ||
const getRequiredSigners = (body) => __awaiter(void 0, void 0, void 0, function* () { | ||
const signers = yield body.requiredSigners(); | ||
const signersArray = []; | ||
for (let i = 0; i < (yield signers.len()); i++) { | ||
const signer = yield signers.get(i); | ||
signersArray.push(signer); | ||
} | ||
return signersArray; | ||
}); | ||
const signRawTransaction = (wasm, cbor, pKeys) => __awaiter(void 0, void 0, void 0, function* () { | ||
const fixedTx = yield wasm.FixedTransaction.fromHex(cbor); | ||
if (!fixedTx) | ||
throw new Error('invalid tx hex'); | ||
const body = yield fixedTx.body(); | ||
const txHash = yield wasm.hashTransaction(body); | ||
if (!txHash) | ||
throw new Error('invalid tx hex, could not generate tx hash'); | ||
const witSet = yield fixedTx.witnessSet(); | ||
const vkeys = yield wasm.Vkeywitnesses.new(); | ||
for (let i = 0; i < pKeys.length; i++) { | ||
const vkeyWit = yield wasm.makeVkeyWitness(txHash, pKeys[i]); | ||
if (!vkeyWit) | ||
throw new Error('invalid tx hex, could not generate vkey witness'); | ||
yield vkeys.add(vkeyWit); | ||
} | ||
yield witSet.setVkeys(vkeys); | ||
yield fixedTx.setWitnessSet(yield witSet.toBytes()); | ||
return fixedTx.toBytes(); | ||
}); | ||
exports.signRawTransaction = signRawTransaction; |
@@ -17,2 +17,3 @@ import { SignTransactionRequest } from "@cardano-foundation/ledgerjs-hw-app-cardano"; | ||
export declare const createLedgerPlutusPayload: (params: CreateLedgerPlutusPayloadParams) => Promise<SignTransactionRequest>; | ||
export declare const createEmptyPlutusDatum: (wasm: WasmContract.WasmModuleProxy) => Promise<WasmContract.PlutusData | undefined>; | ||
export {}; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -12,4 +35,5 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createLedgerPlutusPayload = void 0; | ||
exports.createEmptyPlutusDatum = exports.createLedgerPlutusPayload = void 0; | ||
const ledgerjs_hw_app_cardano_1 = require("@cardano-foundation/ledgerjs-hw-app-cardano"); | ||
const WasmContract = __importStar(require("@emurgo/cross-csl-core")); | ||
const ledger_1 = require("./utils/ledger"); | ||
@@ -37,4 +61,4 @@ const createLedgerPlutusPayload = (params) => __awaiter(void 0, void 0, void 0, function* () { | ||
const requiredSigners = yield Promise.all(originalRequiredSigners.map((s) => __awaiter(void 0, void 0, void 0, function* () { | ||
const paymentStakeCredential = yield wasm.StakeCredential.fromKeyhash(s); | ||
const stakeCredential = yield wasm.StakeCredential.fromKeyhash(stakeVKHash); | ||
const paymentStakeCredential = yield wasm.Credential.fromKeyhash(s); | ||
const stakeCredential = yield wasm.Credential.fromKeyhash(stakeVKHash); | ||
const baseAddress = yield wasm.BaseAddress.new(networkId, paymentStakeCredential, stakeCredential); | ||
@@ -93,1 +117,5 @@ const addressing = getAddressAddressing(yield baseAddress.toAddress().then(a => a.toBech32())); | ||
}); | ||
const createEmptyPlutusDatum = (wasm) => __awaiter(void 0, void 0, void 0, function* () { | ||
return yield wasm.PlutusData.fromJson(JSON.stringify({ "constructor": 0, "fields": [] }), WasmContract.PlutusDatumSchema.DetailedSchema); | ||
}); | ||
exports.createEmptyPlutusDatum = createEmptyPlutusDatum; |
@@ -174,3 +174,3 @@ "use strict"; | ||
if (stakingKey && valueInAccount) { | ||
const allUtxosForKey = yield (0, addresses_1.filterAddressesByStakingKey)(wasm, yield wasm.StakeCredential.fromKeyhash(yield stakingKey.hash()), allUtxos, false); | ||
const allUtxosForKey = yield (0, addresses_1.filterAddressesByStakingKey)(wasm, yield wasm.Credential.fromKeyhash(yield stakingKey.hash()), allUtxos, false); | ||
const utxoSum = allUtxosForKey.reduce((sum, utxo) => sum.joinAddMutable((0, assets_1.multiTokenFromRemote)(utxo, networkId)), new multi_token_1.MultiToken([], defaultToken)); | ||
@@ -177,0 +177,0 @@ const differenceAfterTx = yield (0, transactions_1.getDifferenceAfterTx)(wasm, senderUtxos, txBody, allUtxos, stakingKey, defaultToken); |
import { Addressing } from '../models'; | ||
import * as WasmContract from '@emurgo/cross-csl-core'; | ||
import { Bip32PublicKey, StakeCredential } from '@emurgo/cross-csl-core'; | ||
import { Bip32PublicKey, Credential } from '@emurgo/cross-csl-core'; | ||
export declare function normalizeToAddress(wasm: WasmContract.WasmModuleProxy, addr: string): Promise<WasmContract.Address | undefined>; | ||
@@ -8,4 +8,4 @@ export declare function toHexOrBase58(wasm: WasmContract.WasmModuleProxy, address: WasmContract.Address): Promise<string>; | ||
receiver: string; | ||
}>(wasm: WasmContract.WasmModuleProxy, stakingKey: StakeCredential, utxos: ReadonlyArray<T>, acceptTypeMismatch: boolean): Promise<ReadonlyArray<T>>; | ||
export declare function addrContainsAccountKey(wasm: WasmContract.WasmModuleProxy, address: string, targetAccountKey: StakeCredential, acceptTypeMismatch: boolean): Promise<boolean>; | ||
}>(wasm: WasmContract.WasmModuleProxy, stakingKey: Credential, utxos: ReadonlyArray<T>, acceptTypeMismatch: boolean): Promise<ReadonlyArray<T>>; | ||
export declare function addrContainsAccountKey(wasm: WasmContract.WasmModuleProxy, address: string, targetAccountKey: Credential, acceptTypeMismatch: boolean): Promise<boolean>; | ||
export declare const derivePublicByAddressing: (addressing: Addressing, startingFrom: { | ||
@@ -12,0 +12,0 @@ key: Bip32PublicKey; |
@@ -160,3 +160,3 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const credential = yield wasm.StakeCredential.fromKeyhash(yield stakingKey.hash()); | ||
const credential = yield wasm.Credential.fromKeyhash(yield stakingKey.hash()); | ||
if (poolId === null) { | ||
@@ -182,3 +182,3 @@ if (registrationStatus === models_1.RegistrationStatus.Deregister) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const stakeCredential = yield wasm.StakeCredential.fromKeyhash(yield stakingKey.hash()); | ||
const stakeCredential = yield wasm.Credential.fromKeyhash(yield stakingKey.hash()); | ||
const sumInForKey = new multi_token_1.MultiToken([], defaultToken); | ||
@@ -185,0 +185,0 @@ { |
{ | ||
"name": "@emurgo/yoroi-lib", | ||
"version": "0.11.0", | ||
"version": "0.13.0", | ||
"description": "", | ||
@@ -29,3 +29,3 @@ "main": "dist/index.js", | ||
"@cardano-foundation/ledgerjs-hw-app-cardano": "^6.0.0", | ||
"@emurgo/cross-csl-core": "3.1.0", | ||
"@emurgo/cross-csl-core": "^3.4.0", | ||
"@noble/hashes": "^1.3.2", | ||
@@ -37,3 +37,3 @@ "axios": "^0.24.0", | ||
"devDependencies": { | ||
"@emurgo/cross-csl-nodejs": "3.1.0", | ||
"@emurgo/cross-csl-nodejs": "^3.4.1", | ||
"@types/chai": "^4.2.21", | ||
@@ -40,0 +40,0 @@ "@types/mocha": "^9.0.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
279753
71
5007
+ Added@emurgo/cross-csl-core@3.7.0(transitive)
- Removed@emurgo/cross-csl-core@3.1.0(transitive)