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

@emurgo/yoroi-lib-core

Package Overview
Dependencies
Maintainers
3
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@emurgo/yoroi-lib-core - npm Package Compare versions

Comparing version 0.1.5-alpha.20 to 0.2.0-alpha.21

3

dist/errors/index.d.ts

@@ -18,1 +18,4 @@ export declare abstract class BaseError extends Error {

}
export declare class RewardAddressEmptyError extends BaseError {
constructor();
}

10

dist/errors/index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GenericError = exports.NoOutputsError = exports.AssetOverflowError = exports.NotEnoughMoneyToSendError = exports.BaseError = void 0;
exports.RewardAddressEmptyError = exports.GenericError = exports.NoOutputsError = exports.AssetOverflowError = exports.NotEnoughMoneyToSendError = exports.BaseError = void 0;
class BaseError extends Error {

@@ -28,3 +28,3 @@ constructor(id, message) {

constructor() {
super('23f2aa70-7e40-4cae-a113-3f8919ad45ec', 'Asset overflow');
super('23f2aa70-7e40-4cae-a113-3f8919ad45ec', 'No outputs');
}

@@ -39,1 +39,7 @@ }

exports.GenericError = GenericError;
class RewardAddressEmptyError extends BaseError {
constructor() {
super('6ad14231-59f5-405d-8fc1-69a0acb92195', 'Reward address empty');
}
}
exports.RewardAddressEmptyError = RewardAddressEmptyError;
import { BigNumber } from 'bignumber.js';
import { AddressingAddress, CardanoAddressedUtxo, CardanoHaskellConfig, SendToken, Token, TxOptions } from './internals/models';
import { AccountStatePart, AddressingAddress, CardanoAddressedUtxo, CardanoHaskellConfig, SendToken, Token, TxOptions, WithdrawalRequest } from './internals/models';
import { UnsignedTx } from './internals/tx';

@@ -27,2 +27,5 @@ import * as WasmContract from './internals/wasm-contract';

createUnsignedTx(absSlotNumber: BigNumber, utxos: Array<CardanoAddressedUtxo>, receiver: string, changeAddr: AddressingAddress, tokens: Array<SendToken>, config: CardanoHaskellConfig, defaultToken: Token, txOptions: TxOptions): Promise<UnsignedTx>;
createUnsignedWithdrawalTx(accountState: {
[key: string]: null | AccountStatePart;
}, absSlotNumber: BigNumber, utxos: Array<CardanoAddressedUtxo>, withdrawalRequests: Array<WithdrawalRequest>, changeAddr: AddressingAddress, config: CardanoHaskellConfig, txOptions: TxOptions): Promise<UnsignedTx>;
}

@@ -105,2 +105,67 @@ "use strict";

}
createUnsignedWithdrawalTx(accountState, absSlotNumber, utxos, withdrawalRequests, changeAddr, config, txOptions) {
return __awaiter(this, void 0, void 0, function* () {
const certificates = [];
const neededKeys = {
neededHashes: new Set(),
wits: new Set(),
};
const requiredWits = [];
for (const withdrawalRequest of withdrawalRequests) {
const wasmAddr = yield this.Wasm.RewardAddress.fromAddress(yield this.Wasm.Address.fromBytes(Buffer.from(withdrawalRequest.rewardAddress, 'hex')));
if (!wasmAddr.hasValue())
throw new Error(`createUnsignedWithdrawalTx: withdrawal not a reward address`);
const paymentCred = yield wasmAddr.paymentCred();
const keyHash = yield paymentCred.toKeyhash();
if (!keyHash.hasValue())
throw new Error(`Unexpected: withdrawal from a script hash`);
requiredWits.push(keyHash);
if (withdrawalRequest.shouldDeregister) {
certificates.push(yield this.Wasm.Certificate.newStakeDeregistration(yield this.Wasm.StakeDeregistration.new(paymentCred)));
neededKeys.neededHashes.add(Buffer.from(yield paymentCred.toBytes()).toString('hex'));
}
}
const finalWithdrawals = yield Object.keys(accountState).reduce((listPromise, address) => __awaiter(this, void 0, void 0, function* () {
const list = yield listPromise;
const rewardForAddress = accountState[address];
// if key is not registered, we just skip this withdrawal
if (rewardForAddress == null) {
return list;
}
const rewardBalance = new bignumber_js_1.BigNumber(rewardForAddress.remainingAmount);
// if the reward address is empty, we filter it out of the withdrawal list
// although the protocol allows withdrawals of 0 ADA, it's pointless to do
// recall: you may want to undelegate the ADA even if there is 0 ADA in the reward address
// since you may want to get back your deposit
if (rewardBalance.eq(0)) {
return list;
}
const rewardAddress = yield this.Wasm.RewardAddress.fromAddress(yield this.Wasm.Address.fromBytes(Buffer.from(address, 'hex')));
if (!rewardAddress.hasValue()) {
throw new Error(`createUnsignedWithdrawalTx: withdrawal not a reward address`);
}
{
const stakeCredential = yield rewardAddress.paymentCred();
neededKeys.neededHashes.add(Buffer.from(yield stakeCredential.toBytes()).toString('hex'));
}
list.push({
address: rewardAddress,
amount: yield this.Wasm.BigNum.fromStr(rewardForAddress.remainingAmount)
});
return list;
}), Promise.resolve([]));
if (finalWithdrawals.length === 0 && certificates.length === 0) {
throw new errors_1.RewardAddressEmptyError();
}
const protocolParams = {
keyDeposit: yield this._wasmV4.BigNum.fromStr(config.keyDeposit),
linearFee: yield this._wasmV4.LinearFee.new(yield this._wasmV4.BigNum.fromStr(config.linearFee.coefficient), yield this._wasmV4.BigNum.fromStr(config.linearFee.constant)),
minimumUtxoVal: yield this._wasmV4.BigNum.fromStr(config.minimumUtxoVal),
poolDeposit: yield this._wasmV4.BigNum.fromStr(config.poolDeposit),
networkId: config.networkId
};
const unsignedTx = yield this.newAdaUnsignedTx([], changeAddr, utxos, absSlotNumber, protocolParams, certificates, finalWithdrawals, undefined, neededKeys, txOptions, false);
return unsignedTx;
});
}
createUnsignedTxForUtxos(absSlotNumber, receivers, defaultToken, tokens, utxos, config, txOptions) {

@@ -124,3 +189,6 @@ return __awaiter(this, void 0, void 0, function* () {

const receiver = receivers[0];
return yield this.sendAllUnsignedTx(receiver, utxos, absSlotNumber, protocolParams, txMetadata, txOptions);
return yield this.sendAllUnsignedTx(receiver, utxos, absSlotNumber, protocolParams, txMetadata, {
neededHashes: new Set([]),
wits: new Set([]),
}, txOptions);
}

@@ -152,3 +220,3 @@ else {

}
const unsignedTxResponse = yield this.newAdaUnsignedTx(otherAddresses.length === 1
const unsignedTx = yield this.newAdaUnsignedTx(otherAddresses.length === 1
? [

@@ -163,5 +231,8 @@ {

addressing: changeAddr.addressing
}, utxos, absSlotNumber, protocolParams, [], [], txMetadata, txOptions, false);
YoroiLib.logger.debug(`createUnsignedTxForUtxos success`, unsignedTxResponse);
return unsignedTxResponse;
}, utxos, absSlotNumber, protocolParams, [], [], txMetadata, {
neededHashes: new Set([]),
wits: new Set([]),
}, txOptions, false);
YoroiLib.logger.debug(`createUnsignedTxForUtxos success`, unsignedTx);
return unsignedTx;
}

@@ -177,3 +248,3 @@ }

}
sendAllUnsignedTx(receiver, allUtxos, absSlotNumber, protocolParams, auxData, txOptions) {
sendAllUnsignedTx(receiver, allUtxos, absSlotNumber, protocolParams, auxData, neededStakingKeyHashes, txOptions) {
var _a;

@@ -209,3 +280,3 @@ return __awaiter(this, void 0, void 0, function* () {

isDefault: true
}, protocolParams.networkId, (_a = txOptions.metadata) !== null && _a !== void 0 ? _a : []);
}, protocolParams.networkId, neededStakingKeyHashes, (_a = txOptions.metadata) !== null && _a !== void 0 ? _a : []);
});

@@ -278,3 +349,3 @@ }

}
newAdaUnsignedTx(outputs, changeAdaAddr, allUtxos, absSlotNumber, protocolParams, certificates, withdrawals, auxData, txOptions, allowNoOutputs) {
newAdaUnsignedTx(outputs, changeAdaAddr, allUtxos, absSlotNumber, protocolParams, certificates, withdrawals, auxData, neededStakingKeyHashes, txOptions, allowNoOutputs) {
var _a;

@@ -305,3 +376,3 @@ return __awaiter(this, void 0, void 0, function* () {

isDefault: true
}, protocolParams.networkId, (_a = txOptions.metadata) !== null && _a !== void 0 ? _a : []);
}, protocolParams.networkId, neededStakingKeyHashes, (_a = txOptions.metadata) !== null && _a !== void 0 ? _a : []);
});

@@ -308,0 +379,0 @@ }

@@ -8,2 +8,12 @@ import { BigNumber } from 'bignumber.js';

};
export declare type AccountStatePart = {
remainingAmount: string;
rewards: string;
withdrawals: string;
};
export declare type WithdrawalRequest = {
addressing: Addressing;
rewardAddress: string;
shouldDeregister: boolean;
};
export declare type Transaction = {

@@ -10,0 +20,0 @@ hash: string;

@@ -13,2 +13,3 @@ import * as WasmContract from './wasm-contract';

private _ttl;
private _neededStakingKeyHashes;
private _hash;

@@ -24,2 +25,4 @@ private _senderUtxos;

private _encodedTx;
get wasm(): WasmContract.WasmModuleProxy;
get txBody(): WasmContract.TransactionBody;
get senderUtxos(): ReadonlyArray<CardanoAddressedUtxo>;

@@ -43,2 +46,6 @@ get inputs(): ReadonlyArray<{

get ttl(): number | undefined;
get neededStakingKeyHashes(): {
neededHashes: Set<string>;
wits: Set<string>;
};
get hash(): WasmContract.TransactionHash;

@@ -50,3 +57,12 @@ /**

*/
private constructor();
protected constructor(wasm: WasmContract.WasmModuleProxy, txBody: WasmContract.TransactionBody, senderUtxos: CardanoAddressedUtxo[], inputs: ReadonlyArray<{
address: string;
value: MultiTokenValue;
}>, totalInput: MultiTokenValue, outputs: ReadonlyArray<{
address: string;
value: MultiTokenValue;
}>, totalOutput: MultiTokenValue, fee: MultiTokenValue, change: ReadonlyArray<Change>, metadata: ReadonlyArray<TxMetadata>, certificates: WasmContract.Certificates, withdrawals: WasmContract.Withdrawals, ttl: number | undefined, neededStakingKeyHashes: {
neededHashes: Set<string>;
wits: Set<string>;
}, encodedTx: string, hash: WasmContract.TransactionHash);
static new(wasm: WasmContract.WasmModuleProxy, txBuilder: WasmContract.TransactionBuilder, senderUtxos: CardanoAddressedUtxo[], inputs: ReadonlyArray<{

@@ -58,3 +74,6 @@ address: string;

value: MultiTokenValue;
}>, totalOutput: MultiTokenValue, fee: MultiTokenValue, change: ReadonlyArray<Change>, metadata: ReadonlyArray<TxMetadata>): Promise<WasmUnsignedTx>;
}>, totalOutput: MultiTokenValue, fee: MultiTokenValue, change: ReadonlyArray<Change>, neededStakingKeyHashes: {
neededHashes: Set<string>;
wits: Set<string>;
}, metadata: ReadonlyArray<TxMetadata>): Promise<WasmUnsignedTx>;
sign(keyLevel: number, privateKey: string, stakingKeyWits: Set<string>, extraMetadata: TxMetadata[]): Promise<SignedTx>;

@@ -81,2 +100,6 @@ private addWitnesses;

readonly ttl: number | undefined;
readonly neededStakingKeyHashes: {
neededHashes: Set<string>;
wits: Set<string>;
};
readonly encodedTx: string;

@@ -86,2 +109,11 @@ readonly hash: WasmContract.TransactionHash;

}
export declare function genWasmUnsignedTx(wasm: WasmContract.WasmModuleProxy, txBuilder: WasmContract.TransactionBuilder, senderUtxos: CardanoAddressedUtxo[], change: ReadonlyArray<Change>, defaults: Token, networkId: number, metadata: ReadonlyArray<TxMetadata>): Promise<WasmUnsignedTx>;
export interface UnsignedWithdrawalTx extends UnsignedTx {
neededStakingKeyHashes: {
neededHashes: Set<string>;
wits: Set<string>;
};
}
export declare function genWasmUnsignedTx(wasm: WasmContract.WasmModuleProxy, txBuilder: WasmContract.TransactionBuilder, senderUtxos: CardanoAddressedUtxo[], change: ReadonlyArray<Change>, defaults: Token, networkId: number, neededStakingKeyHashes: {
neededHashes: Set<string>;
wits: Set<string>;
}, metadata: ReadonlyArray<TxMetadata>): Promise<WasmUnsignedTx>;

@@ -46,3 +46,3 @@ "use strict";

*/
constructor(wasm, txBody, senderUtxos, inputs, totalInput, outputs, totalOutput, fee, change, metadata, certificates, withdrawals, ttl, encodedTx, hash) {
constructor(wasm, txBody, senderUtxos, inputs, totalInput, outputs, totalOutput, fee, change, metadata, certificates, withdrawals, ttl, neededStakingKeyHashes, encodedTx, hash) {
this._wasm = wasm;

@@ -61,5 +61,12 @@ this._txBody = txBody;

this._ttl = ttl;
this._neededStakingKeyHashes = neededStakingKeyHashes;
this._encodedTx = encodedTx;
this._hash = hash;
}
get wasm() {
return this._wasm;
}
get txBody() {
return this._txBody;
}
get senderUtxos() {

@@ -101,6 +108,9 @@ return this._senderUtxos;

}
get neededStakingKeyHashes() {
return this._neededStakingKeyHashes;
}
get hash() {
return this._hash;
}
static new(wasm, txBuilder, senderUtxos, inputs, totalInput, outputs, totalOutput, fee, change, metadata) {
static new(wasm, txBuilder, senderUtxos, inputs, totalInput, outputs, totalOutput, fee, change, neededStakingKeyHashes, metadata) {
return __awaiter(this, void 0, void 0, function* () {

@@ -113,3 +123,3 @@ const txBody = yield txBuilder.build();

const hash = yield wasm.hashTransaction(txBody);
return new WasmUnsignedTx(wasm, txBody, senderUtxos, inputs, totalInput, outputs, totalOutput, fee, change, metadata, certs, withdrawals, ttl, Buffer.from(txBytes).toString('hex'), hash);
return new WasmUnsignedTx(wasm, txBody, senderUtxos, inputs, totalInput, outputs, totalOutput, fee, change, metadata, certs, withdrawals, ttl, neededStakingKeyHashes, Buffer.from(txBytes).toString('hex'), hash);
});

@@ -216,5 +226,5 @@ }

exports.WasmUnsignedTx = WasmUnsignedTx;
function genWasmUnsignedTx(wasm, txBuilder, senderUtxos, change, defaults, networkId, metadata) {
function genWasmUnsignedTx(wasm, txBuilder, senderUtxos, change, defaults, networkId, neededStakingKeyHashes, metadata) {
return __awaiter(this, void 0, void 0, function* () {
return yield WasmUnsignedTx.new(wasm, txBuilder, senderUtxos, yield genWasmUnsignedTxInputs(txBuilder, senderUtxos, networkId), yield genWasmUnsignedTxTotalInput(txBuilder, change, defaults), yield genWasmUnsignedTxOutputs(txBuilder, networkId), yield genWasmUnsignedTxTotalOutput(txBuilder, defaults), yield genWasmUnsignedTxFee(txBuilder, defaults, networkId), change, metadata);
return yield WasmUnsignedTx.new(wasm, txBuilder, senderUtxos, yield genWasmUnsignedTxInputs(txBuilder, senderUtxos, networkId), yield genWasmUnsignedTxTotalInput(txBuilder, change, defaults), yield genWasmUnsignedTxOutputs(txBuilder, networkId), yield genWasmUnsignedTxTotalOutput(txBuilder, defaults), yield genWasmUnsignedTxFee(txBuilder, defaults, networkId), change, neededStakingKeyHashes, metadata);
});

@@ -221,0 +231,0 @@ }

@@ -344,2 +344,3 @@ export declare const EXCEPTIONS: {

abstract toPublic(): Promise<PublicKey>;
abstract toBech32(): Promise<string>;
abstract asBytes(): Promise<Uint8Array>;

@@ -349,2 +350,4 @@ abstract sign(message: Uint8Array): Promise<Ed25519Signature>;

static fromNormalBytes(bytes: Uint8Array): Promise<PrivateKey>;
static generateEd25519(): Promise<PrivateKey>;
static generate_ed25519extended(): Promise<PrivateKey>;
}

@@ -351,0 +354,0 @@ export declare abstract class Bip32PrivateKey extends _Ptr {

@@ -308,2 +308,8 @@ "use strict";

}
static generateEd25519() {
throw exports.EXCEPTIONS.SHOULD_BE_OVERWRITTEN;
}
static generate_ed25519extended() {
throw exports.EXCEPTIONS.SHOULD_BE_OVERWRITTEN;
}
}

@@ -310,0 +316,0 @@ exports.PrivateKey = PrivateKey;

{
"name": "@emurgo/yoroi-lib-core",
"version": "0.1.5-alpha.20",
"version": "0.2.0-alpha.21",
"description": "",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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