@emurgo/yoroi-lib-core
Advanced tools
Comparing version 0.1.0-alpha.12 to 0.1.1-alpha.13
import { BigNumber } from 'bignumber.js'; | ||
import { AddressingAddress, AddressingUtxo, CardanoHaskellConfig, DefaultTokenEntry, SendToken, TxOptions } from './internals/models'; | ||
import { AddressingAddress, AddressingUtxo, CardanoHaskellConfig, SendToken, Token, TxOptions } from './internals/models'; | ||
import { UnsignedTx } from './internals/tx'; | ||
@@ -26,3 +26,3 @@ import * as WasmContract from './internals/wasm-contract'; | ||
decryptWithPassword(password: string, data: string): Promise<string>; | ||
createUnsignedTx(absSlotNumber: BigNumber, utxos: Array<AddressingUtxo>, receiver: string, changeAddr: AddressingAddress, tokens: Array<SendToken>, config: CardanoHaskellConfig, defaultToken: DefaultTokenEntry, txOptions: TxOptions): Promise<UnsignedTx>; | ||
createUnsignedTx(absSlotNumber: BigNumber, utxos: Array<AddressingUtxo>, receiver: string, changeAddr: AddressingAddress, tokens: Array<SendToken>, config: CardanoHaskellConfig, defaultToken: Token, txOptions: TxOptions): Promise<UnsignedTx>; | ||
} |
@@ -143,3 +143,3 @@ "use strict"; | ||
if (next.addressing == null) { | ||
arr.push({ address: next.address }); | ||
arr.push(next.address); | ||
return arr; | ||
@@ -155,3 +155,3 @@ } | ||
{ | ||
address: otherAddresses[0].address, | ||
address: otherAddresses[0], | ||
amount: (0, assets_1.buildSendTokenList)(defaultToken, tokens, utxos.map((utxo) => (0, assets_1.multiTokenFromRemote)(utxo, protocolParams.networkId))) | ||
@@ -204,4 +204,5 @@ } | ||
return yield (0, tx_1.genWasmUnsignedTx)(this.Wasm, unsignedTxResponse.txBuilder, addressedUtxos, unsignedTxResponse.change, { | ||
defaultNetworkId: protocolParams.networkId, | ||
defaultIdentifier: models_1.PRIMARY_ASSET_CONSTANTS.Cardano | ||
networkId: protocolParams.networkId, | ||
identifier: models_1.PRIMARY_ASSET_CONSTANTS.Cardano, | ||
isDefault: true | ||
}, protocolParams.networkId, (_a = txOptions.metadata) !== null && _a !== void 0 ? _a : []); | ||
@@ -261,4 +262,5 @@ }); | ||
values: yield (0, assets_1.multiTokenFromCardanoValue)(yield txBuilder.getExplicitOutput(), { | ||
defaultNetworkId: protocolParams.networkId, | ||
defaultIdentifier: models_1.PRIMARY_ASSET_CONSTANTS.Cardano | ||
networkId: protocolParams.networkId, | ||
identifier: models_1.PRIMARY_ASSET_CONSTANTS.Cardano, | ||
isDefault: true | ||
}) | ||
@@ -298,4 +300,5 @@ } | ||
return yield (0, tx_1.genWasmUnsignedTx)(this.Wasm, unsignedTxResponse.txBuilder, addressedUtxos, unsignedTxResponse.change, { | ||
defaultNetworkId: protocolParams.networkId, | ||
defaultIdentifier: models_1.PRIMARY_ASSET_CONSTANTS.Cardano | ||
networkId: protocolParams.networkId, | ||
identifier: models_1.PRIMARY_ASSET_CONSTANTS.Cardano, | ||
isDefault: true | ||
}, protocolParams.networkId, (_a = txOptions.metadata) !== null && _a !== void 0 ? _a : []); | ||
@@ -567,4 +570,5 @@ }); | ||
.then((x) => x.checkedSub(outputBeforeChange)), { | ||
defaultNetworkId: protocolParams.networkId, | ||
defaultIdentifier: models_1.PRIMARY_ASSET_CONSTANTS.Cardano | ||
networkId: protocolParams.networkId, | ||
identifier: models_1.PRIMARY_ASSET_CONSTANTS.Cardano, | ||
isDefault: true | ||
}); | ||
@@ -571,0 +575,0 @@ return changeWasAdded |
@@ -11,10 +11,7 @@ import { BigNumber } from 'bignumber.js'; | ||
}; | ||
export declare type UtxoTransactionOutput = { | ||
outputIndex: number; | ||
}; | ||
export declare type UtxoTxOutput = { | ||
export declare type Utxo = { | ||
transaction: Transaction; | ||
utxoTransactionOutput: UtxoTransactionOutput; | ||
index: number; | ||
tokens: Array<{ | ||
tokenList: TokenList; | ||
amount: string; | ||
token: Token; | ||
@@ -24,18 +21,18 @@ }>; | ||
export declare type AddressingUtxo = AddressingAddress & { | ||
output: UtxoTxOutput; | ||
output: Utxo; | ||
}; | ||
export declare type CardanoAddressedUtxo = RemoteUnspentOutput & Addressing; | ||
export declare type Value = { | ||
export declare type CardanoAddressedUtxo = RemoteUnspentOutput & { | ||
addressing: Addressing; | ||
}; | ||
export declare type Change = AddressingAddress & { | ||
values: MultiToken; | ||
}; | ||
export declare type Change = AddressingAddress & Value; | ||
export declare type AddressingAddress = Address & Addressing; | ||
export declare type Address = { | ||
address: string; | ||
export declare type AddressingAddress = { | ||
address: Address; | ||
addressing: Addressing; | ||
}; | ||
export declare type Address = string; | ||
export declare type Addressing = { | ||
addressing: { | ||
path: number[]; | ||
startLevel: number; | ||
}; | ||
path: number[]; | ||
startLevel: number; | ||
}; | ||
@@ -63,5 +60,2 @@ export declare type TxOutput = { | ||
}; | ||
export declare type TokenList = { | ||
amount: string; | ||
}; | ||
export declare type Token = { | ||
@@ -72,6 +66,2 @@ identifier: string; | ||
}; | ||
export declare type DefaultTokenEntry = { | ||
defaultNetworkId: number; | ||
defaultIdentifier: string; | ||
}; | ||
export declare type TokenEntry = { | ||
@@ -82,5 +72,5 @@ amount: BigNumber; | ||
}; | ||
export declare type MultiTokenConstruct = { | ||
export declare type MultiTokenValue = { | ||
values: Array<TokenEntry>; | ||
defaults: DefaultTokenEntry; | ||
defaults: Token; | ||
}; | ||
@@ -87,0 +77,0 @@ export declare type TxOptions = { |
import { BigNumber } from 'bignumber.js'; | ||
import { DefaultTokenEntry, TokenEntry } from './models'; | ||
import { Token, TokenEntry } from './models'; | ||
export declare class MultiToken { | ||
values: Array<TokenEntry>; | ||
defaults: DefaultTokenEntry; | ||
constructor(values: Array<TokenEntry>, defaults: DefaultTokenEntry); | ||
defaults: Token; | ||
constructor(values: Array<TokenEntry>, defaults: Token); | ||
_checkNetworkId(networkId: number): void; | ||
@@ -8,0 +8,0 @@ get(identifier: string): BigNumber | undefined; |
@@ -11,4 +11,4 @@ "use strict"; | ||
this.add({ | ||
identifier: defaults.defaultIdentifier, | ||
networkId: defaults.defaultNetworkId, | ||
identifier: defaults.identifier, | ||
networkId: defaults.networkId, | ||
amount: new bignumber_js_1.BigNumber(0) | ||
@@ -19,3 +19,3 @@ }); | ||
_checkNetworkId(networkId) { | ||
const ownNetworkId = this.defaults.defaultNetworkId; | ||
const ownNetworkId = this.defaults.networkId; | ||
if (ownNetworkId !== networkId) { | ||
@@ -44,3 +44,3 @@ throw new Error(`MultiToken: network mismatch ${ownNetworkId} - ${networkId}`); | ||
// However, we must keep a value of 0 for the default entry | ||
if (identifier === this.defaults.defaultIdentifier) { | ||
if (identifier === this.defaults.identifier) { | ||
return; | ||
@@ -90,8 +90,8 @@ } | ||
getDefaultEntry() { | ||
return this.values.filter((value) => value.networkId === this.defaults.defaultNetworkId && | ||
value.identifier === this.defaults.defaultIdentifier)[0]; | ||
return this.values.filter((value) => value.networkId === this.defaults.networkId && | ||
value.identifier === this.defaults.identifier)[0]; | ||
} | ||
nonDefaultEntries() { | ||
return this.values.filter((value) => !(value.networkId === this.defaults.defaultNetworkId && | ||
value.identifier === this.defaults.defaultIdentifier)); | ||
return this.values.filter((value) => !(value.networkId === this.defaults.networkId && | ||
value.identifier === this.defaults.identifier)); | ||
} | ||
@@ -98,0 +98,0 @@ asMap() { |
import * as WasmContract from './wasm-contract'; | ||
import { CardanoAddressedUtxo, Change, DefaultTokenEntry, MultiTokenConstruct, TxMetadata } from './models'; | ||
import { CardanoAddressedUtxo, Change, Token, MultiTokenValue, TxMetadata } from './models'; | ||
export interface SignedTx { | ||
@@ -26,11 +26,11 @@ id: string; | ||
address: string; | ||
value: MultiTokenConstruct; | ||
value: MultiTokenValue; | ||
}>; | ||
get totalInput(): MultiTokenConstruct; | ||
get totalInput(): MultiTokenValue; | ||
get outputs(): ReadonlyArray<{ | ||
address: string; | ||
value: MultiTokenConstruct; | ||
value: MultiTokenValue; | ||
}>; | ||
get totalOutput(): MultiTokenConstruct; | ||
get fee(): MultiTokenConstruct; | ||
get totalOutput(): MultiTokenValue; | ||
get fee(): MultiTokenValue; | ||
get change(): ReadonlyArray<Change>; | ||
@@ -51,7 +51,7 @@ get metadata(): ReadonlyArray<TxMetadata>; | ||
address: string; | ||
value: MultiTokenConstruct; | ||
}>, totalInput: MultiTokenConstruct, outputs: ReadonlyArray<{ | ||
value: MultiTokenValue; | ||
}>, totalInput: MultiTokenValue, outputs: ReadonlyArray<{ | ||
address: string; | ||
value: MultiTokenConstruct; | ||
}>, totalOutput: MultiTokenConstruct, fee: MultiTokenConstruct, change: ReadonlyArray<Change>, metadata: ReadonlyArray<TxMetadata>): Promise<WasmUnsignedTx>; | ||
value: MultiTokenValue; | ||
}>, totalOutput: MultiTokenValue, fee: MultiTokenValue, change: ReadonlyArray<Change>, metadata: ReadonlyArray<TxMetadata>): Promise<WasmUnsignedTx>; | ||
sign(keyLevel: number, privateKey: string, stakingKeyWits: Set<string>, extraMetadata: TxMetadata[]): Promise<SignedTx>; | ||
@@ -64,11 +64,11 @@ private addWitnesses; | ||
address: string; | ||
value: MultiTokenConstruct; | ||
value: MultiTokenValue; | ||
}>; | ||
readonly totalInput: MultiTokenConstruct; | ||
readonly totalInput: MultiTokenValue; | ||
readonly outputs: ReadonlyArray<{ | ||
address: string; | ||
value: MultiTokenConstruct; | ||
value: MultiTokenValue; | ||
}>; | ||
readonly totalOutput: MultiTokenConstruct; | ||
readonly fee: MultiTokenConstruct; | ||
readonly totalOutput: MultiTokenValue; | ||
readonly fee: MultiTokenValue; | ||
readonly change: ReadonlyArray<Change>; | ||
@@ -83,2 +83,2 @@ readonly metadata: ReadonlyArray<TxMetadata>; | ||
} | ||
export declare function genWasmUnsignedTx(wasm: WasmContract.WasmModuleProxy, txBuilder: WasmContract.TransactionBuilder, senderUtxos: CardanoAddressedUtxo[], change: ReadonlyArray<Change>, defaults: DefaultTokenEntry, networkId: number, metadata: ReadonlyArray<TxMetadata>): Promise<WasmUnsignedTx>; | ||
export declare function genWasmUnsignedTx(wasm: WasmContract.WasmModuleProxy, txBuilder: WasmContract.TransactionBuilder, senderUtxos: CardanoAddressedUtxo[], change: ReadonlyArray<Change>, defaults: Token, networkId: number, metadata: ReadonlyArray<TxMetadata>): Promise<WasmUnsignedTx>; |
@@ -187,3 +187,3 @@ "use strict"; | ||
} | ||
return yield (0, crypto_1.derivePrivateByAddressing)(utxo, { | ||
return yield (0, crypto_1.derivePrivateByAddressing)(utxo.addressing, { | ||
level: keyLevel, | ||
@@ -270,4 +270,5 @@ key: signingKey | ||
const ma = yield (0, assets_1.multiTokenFromCardanoValue)(yield output.amount(), { | ||
defaultIdentifier: models_1.PRIMARY_ASSET_CONSTANTS.Cardano, | ||
defaultNetworkId: networkId | ||
identifier: models_1.PRIMARY_ASSET_CONSTANTS.Cardano, | ||
networkId: networkId, | ||
isDefault: true | ||
}); | ||
@@ -274,0 +275,0 @@ values.push({ |
import { MultiToken } from '../multi-token'; | ||
import { DefaultTokenEntry, RemoteUnspentOutput, SendToken } from '../models'; | ||
import { Token, RemoteUnspentOutput, SendToken } from '../models'; | ||
import * as WasmContract from '../wasm-contract'; | ||
export declare function cardanoValueFromMultiToken(wasm: WasmContract.WasmModuleProxy, tokens: MultiToken): Promise<WasmContract.Value>; | ||
export declare function multiTokenFromCardanoValue(value: WasmContract.Value, defaults: DefaultTokenEntry): Promise<MultiToken>; | ||
export declare function multiTokenFromCardanoValue(value: WasmContract.Value, defaults: Token): Promise<MultiToken>; | ||
export declare function cardanoAssetToIdentifier(policyId: WasmContract.ScriptHash, name: WasmContract.AssetName): Promise<string>; | ||
@@ -11,3 +11,3 @@ export declare function identifierToCardanoAsset(wasm: WasmContract.WasmModuleProxy, identifier: string): Promise<{ | ||
}>; | ||
export declare function buildSendTokenList(defaultToken: DefaultTokenEntry, tokens: SendToken[], utxos: Array<MultiToken>): MultiToken; | ||
export declare function buildSendTokenList(defaultToken: Token, tokens: SendToken[], utxos: Array<MultiToken>): MultiToken; | ||
export declare function multiTokenFromRemote(utxo: RemoteUnspentOutput, networkId: number): MultiToken; | ||
@@ -14,0 +14,0 @@ export declare function hasSendAllDefault(tokens: Array<SendToken>): boolean; |
@@ -44,4 +44,4 @@ "use strict"; | ||
amount: new bignumber_js_1.BigNumber(yield coin.toStr()), | ||
identifier: defaults.defaultIdentifier, | ||
networkId: defaults.defaultNetworkId | ||
identifier: defaults.identifier, | ||
networkId: defaults.networkId | ||
}); | ||
@@ -52,3 +52,3 @@ for (const token of yield parseTokenList(yield value.multiasset())) { | ||
identifier: token.assetId, | ||
networkId: defaults.defaultNetworkId | ||
networkId: defaults.networkId | ||
}); | ||
@@ -122,4 +122,5 @@ } | ||
const result = new multi_token_1.MultiToken([], { | ||
defaultNetworkId: networkId, | ||
defaultIdentifier: models_1.PRIMARY_ASSET_CONSTANTS.Cardano | ||
networkId: networkId, | ||
identifier: models_1.PRIMARY_ASSET_CONSTANTS.Cardano, | ||
isDefault: true | ||
}); | ||
@@ -126,0 +127,0 @@ result.add({ |
@@ -46,8 +46,8 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (startingFrom.level + 1 < addressing.addressing.startLevel) { | ||
if (startingFrom.level + 1 < addressing.startLevel) { | ||
throw new Error(`derivePrivateByAddressing: keyLevel < startLevel`); | ||
} | ||
let derivedKey = startingFrom.key; | ||
for (let i = startingFrom.level - addressing.addressing.startLevel + 1; i < addressing.addressing.path.length; i++) { | ||
derivedKey = yield derivedKey.derive(addressing.addressing.path[i]); | ||
for (let i = startingFrom.level - addressing.startLevel + 1; i < addressing.path.length; i++) { | ||
derivedKey = yield derivedKey.derive(addressing.path[i]); | ||
} | ||
@@ -54,0 +54,0 @@ return derivedKey; |
@@ -81,4 +81,5 @@ "use strict"; | ||
const defaultEntry = { | ||
defaultNetworkId: protocolParams.networkId, | ||
defaultIdentifier: models_1.PRIMARY_ASSET_CONSTANTS.Cardano | ||
networkId: protocolParams.networkId, | ||
identifier: models_1.PRIMARY_ASSET_CONSTANTS.Cardano, | ||
isDefault: true | ||
}; | ||
@@ -101,3 +102,3 @@ const tokenSetInInput = new Set(input.assets.map((asset) => asset.assetId)); | ||
const onlyDefaultEntry = includedTargets.length === 1 && | ||
includedTargets[0].identifier === defaultEntry.defaultIdentifier; | ||
includedTargets[0].identifier === defaultEntry.identifier; | ||
// ignore UTXO that contribute less than their fee if they also don't contribute a token | ||
@@ -149,7 +150,7 @@ if (onlyDefaultEntry && excludeIfSmall) { | ||
if (next.token.identifier === models_1.PRIMARY_ASSET_CONSTANTS.Cardano) { | ||
acc.amount = acc.amount.plus(next.tokenList.amount); | ||
acc.amount = acc.amount.plus(next.amount); | ||
} | ||
else { | ||
acc.tokens.push({ | ||
amount: next.tokenList.amount, | ||
amount: next.amount, | ||
tokenId: next.token.identifier | ||
@@ -176,5 +177,5 @@ }); | ||
txHash: utxo.output.transaction.hash, | ||
txIndex: utxo.output.utxoTransactionOutput.outputIndex, | ||
txIndex: utxo.output.index, | ||
utxoId: utxo.output.transaction.hash + | ||
utxo.output.utxoTransactionOutput.outputIndex, | ||
utxo.output.index, | ||
addressing: utxo.addressing, | ||
@@ -181,0 +182,0 @@ assets |
{ | ||
"name": "@emurgo/yoroi-lib-core", | ||
"version": "0.1.0-alpha.12", | ||
"version": "0.1.1-alpha.13", | ||
"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
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
227422
4122