Skip to content

Commit

Permalink
Merge pull request #3309 from Emurgo/fix/YOEXT-783/consistent-csl-ver
Browse files Browse the repository at this point in the history
use consistently cardano-serialization-lib version 12
  • Loading branch information
vsubhuman authored Oct 12, 2023
2 parents 332adce + 0ed7eb0 commit 889f1d1
Show file tree
Hide file tree
Showing 26 changed files with 178 additions and 113 deletions.
10 changes: 5 additions & 5 deletions packages/yoroi-extension/app/api/ada/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1548,7 +1548,7 @@ export default class AdaApi {
);

const allUtxosForKey = filterAddressesByStakingKey<ElementOf<IGetAllUtxosResponse>>(
RustModule.WalletV4.StakeCredential.from_keyhash(stakingKey.hash()),
RustModule.WalletV4.Credential.from_keyhash(stakingKey.hash()),
allUtxo,
false,
);
Expand Down Expand Up @@ -1578,7 +1578,7 @@ export default class AdaApi {

const stakeCredentialHex = RustModule.WasmScope(Scope => {
return Buffer.from(
Scope.WalletV4.StakeCredential
Scope.WalletV4.Credential
.from_keyhash(stakingKey.hash())
.to_bytes()
).toString('hex')
Expand Down Expand Up @@ -2166,8 +2166,8 @@ export default class AdaApi {
const chainNetworkId = Number.parseInt(config.ChainNetworkId, 10);
const receiveAddress = RustModule.WalletV4.BaseAddress.new(
chainNetworkId,
RustModule.WalletV4.StakeCredential.from_keyhash(firstInternalPayment),
RustModule.WalletV4.StakeCredential.from_keyhash(stakingKey),
RustModule.WalletV4.Credential.from_keyhash(firstInternalPayment),
RustModule.WalletV4.Credential.from_keyhash(stakingKey),
);

const addresses = [
Expand Down Expand Up @@ -2571,7 +2571,7 @@ function getDifferenceAfterTx(
): MultiToken {

const accountKeyString = RustModule.WasmScope(Scope => {
const stakeCredential = Scope.WalletV4.StakeCredential.from_keyhash(stakingKey.hash());
const stakeCredential = Scope.WalletV4.Credential.from_keyhash(stakingKey.hash());
return Buffer.from(stakeCredential.to_bytes()).toString('hex')
})

Expand Down
4 changes: 4 additions & 0 deletions packages/yoroi-extension/app/api/ada/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,8 @@ test('create tx', async () => {
certs: null,
collateral: null,
collateral_return: null,
current_treasury_value: null,
donation: null,
fee: '187369',
inputs: [
{
Expand Down Expand Up @@ -613,6 +615,8 @@ test('create tx', async () => {
ttl: '70866176',
update: null,
validity_start_interval: null,
voting_procedures: null,
voting_proposals: null,
withdrawals: null
},
is_valid: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test('Generate Catalyst registration tx', async () => {
// stake_test1uzhr5zn6akj2affzua8ylcm8t872spuf5cf6tzjrvnmwemcehgcjm (e0ae3a0a7aeda4aea522e74e4fe36759fca80789a613a58a4364f6ecef)
const address = Scope.WalletV4.RewardAddress.new(
Scope.WalletV4.NetworkInfo.testnet().network_id(),
Scope.WalletV4.StakeCredential.from_keyhash(stakePrivateKey.to_public().hash()),
Scope.WalletV4.Credential.from_keyhash(stakePrivateKey.to_public().hash()),
);

const nonce = 1234;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ export function genBaseAddressBatchFunc(
return (
indices: Array<number>
) => {
const stakeKey = RustModule.WalletV4.StakeCredential.from_keyhash(stakingKey.hash());
const stakeKey = RustModule.WalletV4.Credential.from_keyhash(stakingKey.hash());
return indices.map(i => {
const addressKey = addressChain.derive(i).to_raw_key();
const paymentKey = RustModule.WalletV4.StakeCredential.from_keyhash(addressKey.hash());
const paymentKey = RustModule.WalletV4.Credential.from_keyhash(addressKey.hash());
const address = RustModule.WalletV4.BaseAddress.new(
chainNetworkId,
paymentKey,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const MAX_TX_BYTES = 16384;
type RustModuleLoadFlags = 'dontLoadMessagesSigning';

function isWasmPointer(o: ?any): boolean {
return o != null && (typeof o.ptr === 'number') && (typeof o.free === 'function');
return o != null && (typeof o.__wbg_ptr === 'number') && (typeof o.free === 'function');
}

/*
Expand Down Expand Up @@ -70,7 +70,7 @@ function createWasmScope(): {|
* This way ANY wasm pointer produced within the callback will be automatically destroyed,
* but only as long as it's created using the injected proxied module reference.
*/
const scope: Array<{ ptr: number, free: () => void, ... }> = [];
const scope: Array<{ __wbg_ptr: number, free: () => void, ... }> = [];
function recursiveProxy<E>(originalObject: E): E {
if (!isProxiable(originalObject)) {
return originalObject;
Expand Down Expand Up @@ -136,13 +136,13 @@ function createWasmScope(): {|
free: () => {
scope.forEach(x => {
// Checking just to avoid a null-pointer crash
if (x.ptr !== 0) {
if (x.__wbg_ptr !== 0) {
x.free()
}
});
},
size: () => scope.length,
isFree: () => scope.every(x => x.ptr === 0),
isFree: () => scope.every(x => x.__wbg_ptr === 0),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function fixAddresses(

const enterpriseAddr = RustModule.WalletV4.EnterpriseAddress.new(
Number.parseInt(config.ChainNetworkId, 10),
RustModule.WalletV4.StakeCredential.from_keyhash(
RustModule.WalletV4.Credential.from_keyhash(
RustModule.WalletV4.Ed25519KeyHash.from_bech32(address)
)
);
Expand Down Expand Up @@ -422,7 +422,7 @@ export function getSingleAddressString(
if (path[0] === WalletTypePurpose.CIP1852) {
const addr = RustModule.WalletV4.EnterpriseAddress.new(
Number.parseInt(baseConfig.ChainNetworkId, 10),
RustModule.WalletV4.StakeCredential.from_keyhash(
RustModule.WalletV4.Credential.from_keyhash(
derivedKey.to_public().to_raw_key().hash()
),
);
Expand Down Expand Up @@ -453,10 +453,10 @@ export function getMangledAddressString(
if (path[0] === WalletTypePurpose.CIP1852) {
const addr = RustModule.WalletV4.BaseAddress.new(
Number.parseInt(baseConfig.ChainNetworkId, 10),
RustModule.WalletV4.StakeCredential.from_keyhash(
RustModule.WalletV4.Credential.from_keyhash(
derivedKey.to_public().to_raw_key().hash()
),
RustModule.WalletV4.StakeCredential.from_keyhash(
RustModule.WalletV4.Credential.from_keyhash(
RustModule.WalletV4.Ed25519KeyHash.from_bytes(
stakingKey
)
Expand Down Expand Up @@ -494,10 +494,10 @@ export function getAddressForType(
const stakingKey = derivePath(rootKey, newPath);
const addr = RustModule.WalletV4.BaseAddress.new(
Number.parseInt(baseConfig.ChainNetworkId, 10),
RustModule.WalletV4.StakeCredential.from_keyhash(
RustModule.WalletV4.Credential.from_keyhash(
derivedKey.to_public().to_raw_key().hash()
),
RustModule.WalletV4.StakeCredential.from_keyhash(
RustModule.WalletV4.Credential.from_keyhash(
stakingKey.to_public().to_raw_key().hash()
),
);
Expand All @@ -509,7 +509,7 @@ export function getAddressForType(
case CoreAddressTypes.CARDANO_ENTERPRISE: {
const addr = RustModule.WalletV4.EnterpriseAddress.new(
Number.parseInt(baseConfig.ChainNetworkId, 10),
RustModule.WalletV4.StakeCredential.from_keyhash(
RustModule.WalletV4.Credential.from_keyhash(
derivedKey.to_public().to_raw_key().hash()
),
);
Expand All @@ -518,7 +518,7 @@ export function getAddressForType(
case CoreAddressTypes.CARDANO_REWARD: {
const addr = RustModule.WalletV4.RewardAddress.new(
Number.parseInt(baseConfig.ChainNetworkId, 10),
RustModule.WalletV4.StakeCredential.from_keyhash(
RustModule.WalletV4.Credential.from_keyhash(
derivedKey.to_public().to_raw_key().hash()
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export async function getDelegatedBalance(

export function addrContainsAccountKey(
address: string,
targetAccountKey: RustModule.WalletV4.StakeCredential | string,
targetAccountKey: RustModule.WalletV4.Credential | string,
acceptTypeMismatch: boolean,
): boolean {
const wasmAddr = normalizeToAddress(address);
Expand Down Expand Up @@ -83,7 +83,7 @@ export function addrContainsAccountKey(
}

export function filterAddressesByStakingKey<T: { +address: string, ... }>(
stakingKey: RustModule.WalletV4.StakeCredential,
stakingKey: RustModule.WalletV4.Credential,
utxos: $ReadOnlyArray<$ReadOnly<T>>,
acceptTypeMismatch: boolean,
): $ReadOnlyArray<$ReadOnly<T>> {
Expand Down Expand Up @@ -290,7 +290,7 @@ export function createCertificate(
isRegistered: boolean,
poolRequest: void | string,
): Array<RustModule.WalletV4.Certificate> {
const credential = RustModule.WalletV4.StakeCredential.from_keyhash(
const credential = RustModule.WalletV4.Credential.from_keyhash(
stakingKey.hash()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2601,7 +2601,7 @@ async function certificateToDb(
// and in most cases, people generate these addresses through the CLI anyway
{
const rewardAddressHex = RustModule.WasmScope(Module => {
const stakeCredential = Module.WalletV4.StakeCredential
const stakeCredential = Module.WalletV4.Credential
.from_bytes(hexToBytes(stakeCredentialHex));
return bytesToHex(
Module.WalletV4.RewardAddress
Expand All @@ -2617,7 +2617,7 @@ async function certificateToDb(
}
{
const enterpriseAddressHex = RustModule.WasmScope(Module => {
const stakeCredential = Module.WalletV4.StakeCredential
const stakeCredential = Module.WalletV4.Credential
.from_bytes(hexToBytes(stakeCredentialHex));
return Buffer.from(
Module.WalletV4.EnterpriseAddress
Expand Down Expand Up @@ -2711,7 +2711,7 @@ async function certificateToDb(
bytesToHex(rewardAddress.to_address().to_bytes()),
bytesToHex(Module.WalletV4.StakeDelegation
.new(stakeCredentials, poolKeyHash).to_bytes()),
bytesToHex(Module.WalletV4.StakeCredential
bytesToHex(Module.WalletV4.Credential
.from_keyhash(poolKeyHash).to_bytes()),
]
});
Expand Down Expand Up @@ -2768,7 +2768,7 @@ async function certificateToDb(
const owner = cert.poolParams.poolOwners[j];
const ownerKey = Module.WalletV4.Ed25519KeyHash.from_hex(owner);
owners.add(ownerKey);
const ownerStakeCredentialHex = bytesToHex(Module.WalletV4.StakeCredential
const ownerStakeCredentialHex = bytesToHex(Module.WalletV4.Credential
.from_keyhash(ownerKey).to_bytes());
ownerStakeCredentialHexes.push(ownerStakeCredentialHex);
}
Expand Down Expand Up @@ -2807,7 +2807,7 @@ async function certificateToDb(
);

return [
bytesToHex(Module.WalletV4.StakeCredential
bytesToHex(Module.WalletV4.Credential
.from_keyhash(operatorKey).to_bytes()),
bytesToHex(certificate.to_bytes()),
];
Expand Down Expand Up @@ -2864,7 +2864,7 @@ async function certificateToDb(
const poolKeyHash = Module.WalletV4.Ed25519KeyHash
.from_bytes(hexToBytes(cert.poolKeyHash));
return [
bytesToHex(Module.WalletV4.StakeCredential
bytesToHex(Module.WalletV4.Credential
.from_keyhash(poolKeyHash).to_bytes()),
bytesToHex(Module.WalletV4.PoolRetirement
.new(poolKeyHash, cert.epoch).to_bytes()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ export function toEnterprise(

const singleAddr = RustModule.WalletV4.EnterpriseAddress.new(
wasmAddr.network_id(),
RustModule.WalletV4.StakeCredential.from_keyhash(
RustModule.WalletV4.Credential.from_keyhash(
spendingKey
),
);
Expand Down Expand Up @@ -443,7 +443,7 @@ export function getAddressPayload(

export function unwrapStakingKey(
stakingAddress: string,
): RustModule.WalletV4.StakeCredential {
): RustModule.WalletV4.Credential {
const accountAddress =
RustModule.WalletV4.RewardAddress.from_address(
RustModule.WalletV4.Address.from_bytes(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow

import crypto from 'crypto';
import * as crypto from 'crypto';

export function getInitialSeeds(): {|
AddressSeed: number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export async function addShelleyChimericAccountAddress(
|}> {
const accountAddr = RustModule.WalletV4.RewardAddress.new(
chainNetworkId,
RustModule.WalletV4.StakeCredential.from_keyhash(stakingKey.hash()),
RustModule.WalletV4.Credential.from_keyhash(stakingKey.hash()),
);
await addByHash({
...insertRequest,
Expand All @@ -80,15 +80,15 @@ export async function addShelleyUtxoAddress(
|}> {
const wasmEnterpriseAddr = RustModule.WalletV4.EnterpriseAddress.new(
networkId,
RustModule.WalletV4.StakeCredential.from_keyhash(keyHash)
RustModule.WalletV4.Credential.from_keyhash(keyHash)
);
if (wasmEnterpriseAddr == null) {
throw new Error(`${nameof(addShelleyUtxoAddress)} address is not an enterprise address`);
}
const baseAddr = RustModule.WalletV4.BaseAddress.new(
networkId,
wasmEnterpriseAddr.payment_cred(),
RustModule.WalletV4.StakeCredential.from_keyhash(stakingKey.hash())
RustModule.WalletV4.Credential.from_keyhash(stakingKey.hash())
);
await addByHash({
...insertRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ function formatLedgerCertificates(
addressingMap: string => (void | { +path: Array<number>, ... }),
): Array<Certificate> {
const getPath = (
stakeCredential: RustModule.WalletV4.StakeCredential
stakeCredential: RustModule.WalletV4.Credential
): Array<number> => {
const rewardAddr = RustModule.WalletV4.RewardAddress.new(
networkId,
Expand Down Expand Up @@ -849,11 +849,11 @@ export function toLedgerSignRequest(
const hash = Module.WalletV4.Ed25519KeyHash.from_hex(hashHex);
const enterpriseAddress = Module.WalletV4.EnterpriseAddress.new(
networkId,
Module.WalletV4.StakeCredential.from_keyhash(hash),
Module.WalletV4.Credential.from_keyhash(hash),
).to_address().to_hex();
const stakeAddress = Module.WalletV4.RewardAddress.new(
networkId,
Module.WalletV4.StakeCredential.from_keyhash(hash),
Module.WalletV4.Credential.from_keyhash(hash),
).to_address().to_hex();
return ownUtxoAddressMap[enterpriseAddress] ||
ownStakeAddressMap[stakeAddress];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ test('Create Ledger transaction', async () => {
);
const stakingKey = accountKey.derive(ChainDerivations.CHIMERIC_ACCOUNT).derive(0);

const stakeCredential = RustModule.WalletV4.StakeCredential.from_keyhash(
const stakeCredential = RustModule.WalletV4.Credential.from_keyhash(
stakingKey.to_raw_key().to_public().hash()
);
certs.add(RustModule.WalletV4.Certificate.new_stake_registration(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ export async function newAdaUnsignedTxFromUtxo(
auxiliaryData: RustModule.WalletV4.AuxiliaryData | void,
): Promise<V4UnsignedTxUtxoResponse> {
await RustModule.load();
setRuntime(RustModule.CrossCsl.init());
setRuntime(RustModule.CrossCsl.init);

const defaultNetworkConfig = {
linearFee: {
Expand All @@ -563,6 +563,12 @@ export async function newAdaUnsignedTxFromUtxo(
coinsPerUtxoWord: protocolParams.coinsPerUtxoWord,
poolDeposit: protocolParams.poolDeposit,
keyDeposit: protocolParams.keyDeposit,
maxValueSize: 5000,
maxTxSize: 16384,
memPriceFrom: 577,
memPriceTo: 1000,
stepPriceFrom: 721,
stepPriceTo: 10000000,
};

const utxoSet = new UTxOSet(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -905,12 +905,12 @@ describe('Create signed transactions', () => {
[
RustModule.WalletV4.Certificate.new_stake_registration(
RustModule.WalletV4.StakeRegistration.new(
RustModule.WalletV4.StakeCredential.from_keyhash(stakingKey.to_public().hash())
RustModule.WalletV4.Credential.from_keyhash(stakingKey.to_public().hash())
)
),
RustModule.WalletV4.Certificate.new_stake_delegation(
RustModule.WalletV4.StakeDelegation.new(
RustModule.WalletV4.StakeCredential.from_keyhash(stakingKey.to_public().hash()),
RustModule.WalletV4.Credential.from_keyhash(stakingKey.to_public().hash()),
RustModule.WalletV4.Ed25519KeyHash.from_bytes(Buffer.from('1b268f4cba3faa7e36d8a0cc4adca2096fb856119412ee7330f692b5', 'hex'))
)
),
Expand Down Expand Up @@ -963,7 +963,7 @@ describe('Create signed transactions', () => {
),
);
const stakingKey = accountPrivateKey.derive(2).derive(STAKING_KEY_INDEX).to_raw_key();
const stakingKeyCredential = RustModule.WalletV4.StakeCredential.from_keyhash(
const stakingKeyCredential = RustModule.WalletV4.Credential.from_keyhash(
stakingKey.to_public().hash()
);

Expand Down
Loading

0 comments on commit 889f1d1

Please sign in to comment.