diff --git a/.github/workflows/continuous-integration-e2e.yaml b/.github/workflows/continuous-integration-e2e.yaml index f00b5d53fc0..a8752f46617 100644 --- a/.github/workflows/continuous-integration-e2e.yaml +++ b/.github/workflows/continuous-integration-e2e.yaml @@ -52,7 +52,7 @@ jobs: FAUCET_PROVIDER: 'cardano-wallet' FAUCET_PROVIDER_PARAMS: '{"baseUrl":"http://localhost:8090/v2","mnemonic":"fire method repair aware foot tray accuse brother popular olive find account sick rocket next"}' KEY_MANAGEMENT_PROVIDER: 'inMemory' - KEY_MANAGEMENT_PARAMS: '{"accountIndex": 0, "chainId":{"networkId": 0, "networkMagic": 888}, "password":"some_password","mnemonic":"vacant violin soft weird deliver render brief always monitor general maid smart jelly core drastic erode echo there clump dizzy card filter option defense"}' + KEY_MANAGEMENT_PARAMS: '{"bip32Ed25519": "CML", "accountIndex": 0, "chainId":{"networkId": 0, "networkMagic": 888}, "password":"some_password","mnemonic":"vacant violin soft weird deliver render brief always monitor general maid smart jelly core drastic erode echo there clump dizzy card filter option defense"}' ASSET_PROVIDER: 'http' ASSET_PROVIDER_PARAMS: '{"baseUrl":"http://localhost:4000/asset"}' CHAIN_HISTORY_PROVIDER: 'http' diff --git a/.github/workflows/nightly-e2e.yaml b/.github/workflows/nightly-e2e.yaml index daf1e42101b..5fec3630059 100644 --- a/.github/workflows/nightly-e2e.yaml +++ b/.github/workflows/nightly-e2e.yaml @@ -64,7 +64,7 @@ jobs: FAUCET_PROVIDER: 'cardano-wallet' FAUCET_PROVIDER_PARAMS: '{"baseUrl":"http://localhost:8090/v2","mnemonic":"fire method repair aware foot tray accuse brother popular olive find account sick rocket next"}' KEY_MANAGEMENT_PROVIDER: 'inMemory' - KEY_MANAGEMENT_PARAMS: '{"accountIndex": 0, "chainId":{"networkId": 0, "networkMagic": 888}, "password":"some_password","mnemonic":"vacant violin soft weird deliver render brief always monitor general maid smart jelly core drastic erode echo there clump dizzy card filter option defense"}' + KEY_MANAGEMENT_PARAMS: '{"bip32Ed25519": "CML", "accountIndex": 0, "chainId":{"networkId": 0, "networkMagic": 888}, "password":"some_password","mnemonic":"vacant violin soft weird deliver render brief always monitor general maid smart jelly core drastic erode echo there clump dizzy card filter option defense"}' ASSET_PROVIDER: 'http' ASSET_PROVIDER_PARAMS: '{"baseUrl":"http://localhost:4000/asset"}' CHAIN_HISTORY_PROVIDER: 'http' diff --git a/Dockerfile b/Dockerfile index 7c09d24bc04..a61fc0addba 100644 --- a/Dockerfile +++ b/Dockerfile @@ -45,6 +45,8 @@ COPY --from=cardano-services-builder /app/packages/ogmios/dist /app/packages/ogm COPY --from=cardano-services-builder /app/packages/ogmios/package.json /app/packages/ogmios/package.json COPY --from=cardano-services-builder /app/packages/util/dist /app/packages/util/dist COPY --from=cardano-services-builder /app/packages/util/package.json /app/packages/util/package.json +COPY --from=cardano-services-builder /app/packages/crypto/dist /app/packages/crypto/dist +COPY --from=cardano-services-builder /app/packages/crypto/package.json /app/packages/crypto/package.json FROM cardano-services as http-server ARG NETWORK=mainnet diff --git a/packages/cardano-services/package.json b/packages/cardano-services/package.json index c7cbbb5bbbb..1d47f00e6f9 100644 --- a/packages/cardano-services/package.json +++ b/packages/cardano-services/package.json @@ -95,6 +95,7 @@ }, "dependencies": { "@cardano-sdk/core": "^0.7.0", + "@cardano-sdk/crypto": "^0.1.0", "@cardano-sdk/ogmios": "^0.7.0", "@cardano-sdk/util": "^0.7.0", "amqplib": "^0.10.0", diff --git a/packages/cardano-services/src/ChainHistory/DbSyncChainHistory/mappers.ts b/packages/cardano-services/src/ChainHistory/DbSyncChainHistory/mappers.ts index 25db4920dd8..6d1c64ed7f3 100644 --- a/packages/cardano-services/src/ChainHistory/DbSyncChainHistory/mappers.ts +++ b/packages/cardano-services/src/ChainHistory/DbSyncChainHistory/mappers.ts @@ -1,5 +1,5 @@ import { Asset, Cardano } from '@cardano-sdk/core'; -import { BigIntMath, Hash32ByteBase16, HexBlob } from '@cardano-sdk/util'; +import { BigIntMath, HexBlob } from '@cardano-sdk/util'; import { BlockModel, BlockOutputModel, @@ -19,6 +19,7 @@ import { WithCertType, WithdrawalModel } from './types'; +import { Hash32ByteBase16 } from '@cardano-sdk/crypto'; import { isDelegationCertModel, isMirCertModel, @@ -140,7 +141,7 @@ export const mapCertificate = ( ? Cardano.CertificateType.StakeKeyRegistration : Cardano.CertificateType.StakeKeyDeregistration, cert_index: certModel.cert_index, - stakeKeyHash: Cardano.Ed25519KeyHash.fromRewardAccount(certModel.address as unknown as Cardano.RewardAccount) + stakeKeyHash: Cardano.RewardAccount.toHash(Cardano.RewardAccount(certModel.address)) } as WithCertIndex; if (isDelegationCertModel(certModel)) @@ -148,7 +149,7 @@ export const mapCertificate = ( __typename: Cardano.CertificateType.StakeDelegation, cert_index: certModel.cert_index, poolId: certModel.pool_id as unknown as Cardano.PoolId, - stakeKeyHash: Cardano.Ed25519KeyHash.fromRewardAccount(certModel.address as unknown as Cardano.RewardAccount) + stakeKeyHash: Cardano.RewardAccount.toHash(Cardano.RewardAccount(certModel.address)) } as WithCertIndex; return null; diff --git a/packages/cardano-services/src/StakePool/DbSyncStakePoolProvider/mappers.ts b/packages/cardano-services/src/StakePool/DbSyncStakePoolProvider/mappers.ts index b5058a302a9..e8059cc0500 100644 --- a/packages/cardano-services/src/StakePool/DbSyncStakePoolProvider/mappers.ts +++ b/packages/cardano-services/src/StakePool/DbSyncStakePoolProvider/mappers.ts @@ -26,7 +26,8 @@ import { StakePoolResults, StakePoolStatsModel } from './types'; -import { Hash32ByteBase16, bufferToHexString, isNotNil } from '@cardano-sdk/util'; +import { Hash32ByteBase16 } from '@cardano-sdk/crypto'; +import { bufferToHexString, isNotNil } from '@cardano-sdk/util'; import Fraction from 'fraction.js'; const getPoolStatus = ( diff --git a/packages/cardano-services/src/Utxo/DbSyncUtxoProvider/mappers.ts b/packages/cardano-services/src/Utxo/DbSyncUtxoProvider/mappers.ts index 88a13637f06..2951a8d8b9b 100644 --- a/packages/cardano-services/src/Utxo/DbSyncUtxoProvider/mappers.ts +++ b/packages/cardano-services/src/Utxo/DbSyncUtxoProvider/mappers.ts @@ -1,5 +1,6 @@ import { Cardano, SerializationError, SerializationFailure, createUtxoId, jsonToNativeScript } from '@cardano-sdk/core'; -import { Hash32ByteBase16, HexBlob, isNotNil } from '@cardano-sdk/util'; +import { Hash32ByteBase16 } from '@cardano-sdk/crypto'; +import { HexBlob, isNotNil } from '@cardano-sdk/util'; import { ReferenceScriptType, UtxoModel } from './types'; import { generateAssetId } from './util'; diff --git a/packages/cardano-services/test/ChainHistory/DbSyncChainHistoryProvider/mappers.test.ts b/packages/cardano-services/test/ChainHistory/DbSyncChainHistoryProvider/mappers.test.ts index 46390988a4d..4539237bd57 100644 --- a/packages/cardano-services/test/ChainHistory/DbSyncChainHistoryProvider/mappers.test.ts +++ b/packages/cardano-services/test/ChainHistory/DbSyncChainHistoryProvider/mappers.test.ts @@ -25,7 +25,8 @@ import { WithdrawalModel } from '../../../src/ChainHistory/DbSyncChainHistory/types'; import { Cardano } from '@cardano-sdk/core'; -import { Hash32ByteBase16, HexBlob } from '@cardano-sdk/util'; +import { Hash32ByteBase16 } from '@cardano-sdk/crypto'; +import { HexBlob } from '@cardano-sdk/util'; const blockHash = '7a48b034645f51743550bbaf81f8a14771e58856e031eb63844738ca8ad72298'; const poolId = 'pool1zuevzm3xlrhmwjw87ec38mzs02tlkwec9wxpgafcaykmwg7efhh'; @@ -252,12 +253,12 @@ describe('chain history mappers', () => { expect(registrationResult).toEqual>({ __typename: Cardano.CertificateType.StakeKeyRegistration, cert_index: 0, - stakeKeyHash: Cardano.Ed25519KeyHash.fromRewardAccount(Cardano.RewardAccount(stakeAddress)) + stakeKeyHash: Cardano.RewardAccount.toHash(Cardano.RewardAccount(stakeAddress)) }); expect(deregistrationResult).toEqual>({ __typename: Cardano.CertificateType.StakeKeyDeregistration, cert_index: 0, - stakeKeyHash: Cardano.Ed25519KeyHash.fromRewardAccount(Cardano.RewardAccount(stakeAddress)) + stakeKeyHash: Cardano.RewardAccount.toHash(Cardano.RewardAccount(stakeAddress)) }); }); test('map DelegationCertModel to Cardano.StakeDelegationCertificate', () => { @@ -271,7 +272,7 @@ describe('chain history mappers', () => { __typename: Cardano.CertificateType.StakeDelegation, cert_index: 0, poolId: Cardano.PoolId(poolId), - stakeKeyHash: Cardano.Ed25519KeyHash.fromRewardAccount(Cardano.RewardAccount(stakeAddress)) + stakeKeyHash: Cardano.RewardAccount.toHash(Cardano.RewardAccount(stakeAddress)) }); }); }); @@ -315,7 +316,7 @@ describe('chain history mappers', () => { const certificates: Cardano.Certificate[] = [ { __typename: Cardano.CertificateType.StakeKeyRegistration, - stakeKeyHash: Cardano.Ed25519KeyHash.fromRewardAccount(Cardano.RewardAccount(stakeAddress)) + stakeKeyHash: Cardano.RewardAccount.toHash(Cardano.RewardAccount(stakeAddress)) } ]; diff --git a/packages/cardano-services/test/StakePool/DbSyncStakePoolProvider/mappers.test.ts b/packages/cardano-services/test/StakePool/DbSyncStakePoolProvider/mappers.test.ts index 65f4c912134..de1cae9135e 100644 --- a/packages/cardano-services/test/StakePool/DbSyncStakePoolProvider/mappers.test.ts +++ b/packages/cardano-services/test/StakePool/DbSyncStakePoolProvider/mappers.test.ts @@ -15,7 +15,7 @@ import { mapRelay, toStakePoolResults } from '../../../src'; -import { Hash32ByteBase16 } from '@cardano-sdk/util'; +import { Hash32ByteBase16 } from '@cardano-sdk/crypto'; import { mockStakeDistribution } from '../../../../core/test/CardanoNode/mocks'; // eslint-disable-next-line max-statements diff --git a/packages/cardano-services/test/StakePool/StakePoolHttpService.test.ts b/packages/cardano-services/test/StakePool/StakePoolHttpService.test.ts index 2042392bf18..3dcabd9e254 100644 --- a/packages/cardano-services/test/StakePool/StakePoolHttpService.test.ts +++ b/packages/cardano-services/test/StakePool/StakePoolHttpService.test.ts @@ -20,7 +20,7 @@ import { UNLIMITED_CACHE_TTL, createHttpStakePoolExtMetadataService } from '../../src'; -import { Hash32ByteBase16 } from '@cardano-sdk/util'; +import { Hash32ByteBase16 } from '@cardano-sdk/crypto'; import { INFO, createLogger } from 'bunyan'; import { LedgerTipModel, findLedgerTip } from '../../src/util/DbSyncProvider'; import { OgmiosCardanoNode } from '@cardano-sdk/ogmios'; diff --git a/packages/cardano-services/test/Utxo/UtxoHttpService.test.ts b/packages/cardano-services/test/Utxo/UtxoHttpService.test.ts index be3293ccb57..29089b4785b 100644 --- a/packages/cardano-services/test/Utxo/UtxoHttpService.test.ts +++ b/packages/cardano-services/test/Utxo/UtxoHttpService.test.ts @@ -4,7 +4,8 @@ import { Asset, Cardano, ProviderError, ProviderFailure, UtxoProvider } from '@c import { CreateHttpProviderConfig, utxoHttpProvider } from '@cardano-sdk/cardano-services-client'; import { DataMocks } from '../data-mocks'; import { DbSyncUtxoProvider, HttpServer, HttpServerConfig, UtxoHttpService } from '../../src'; -import { Hash32ByteBase16, HexBlob } from '@cardano-sdk/util'; +import { Hash32ByteBase16 } from '@cardano-sdk/crypto'; +import { HexBlob } from '@cardano-sdk/util'; import { INFO, createLogger } from 'bunyan'; import { LedgerTipModel, findLedgerTip } from '../../src/util/DbSyncProvider'; import { OgmiosCardanoNode } from '@cardano-sdk/ogmios'; diff --git a/packages/cardano-services/test/data-mocks/tx.ts b/packages/cardano-services/test/data-mocks/tx.ts index aa08c2eb634..b2be3da3638 100644 --- a/packages/cardano-services/test/data-mocks/tx.ts +++ b/packages/cardano-services/test/data-mocks/tx.ts @@ -1,5 +1,6 @@ import { Cardano } from '@cardano-sdk/core'; -import { Hash32ByteBase16 } from '@cardano-sdk/util'; +import { Ed25519KeyHashHex, Hash32ByteBase16 } from '@cardano-sdk/crypto'; + import merge from 'lodash/merge'; export const valueWithCoinOnly: Cardano.Value = { @@ -97,7 +98,7 @@ export const withAuxiliaryData: Cardano.HydratedTx = merge(withAssets, { export const delegationCertificate: Cardano.StakeDelegationCertificate = { __typename: Cardano.CertificateType.StakeDelegation, poolId: Cardano.PoolId('pool1cjm567pd9eqj7wlpuq2mnsasw2upewq0tchg4n8gktq5k7eepvr'), - stakeKeyHash: Cardano.Ed25519KeyHash('f15db05f56035465bf8900a09bdaa16c3d8b8244fea686524408dd80') + stakeKeyHash: Ed25519KeyHashHex('f15db05f56035465bf8900a09bdaa16c3d8b8244fea686524408dd80') }; export const collateralInputs = [ diff --git a/packages/core/package.json b/packages/core/package.json index 3fa298a4043..08680cdcf17 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -64,6 +64,7 @@ "dependencies": { "@cardano-ogmios/client": "5.5.7", "@cardano-ogmios/schema": "5.5.7", + "@cardano-sdk/crypto": "^0.1.0", "@cardano-sdk/util": "^0.7.0", "@dcspark/cardano-multiplatform-lib-nodejs": "^3.1.1", "@emurgo/cip14-js": "^3.0.1", diff --git a/packages/core/src/Asset/types/NftMetadata.ts b/packages/core/src/Asset/types/NftMetadata.ts index b760ca8e4e9..648d3268db6 100644 --- a/packages/core/src/Asset/types/NftMetadata.ts +++ b/packages/core/src/Asset/types/NftMetadata.ts @@ -1,6 +1,6 @@ /* eslint-disable wrap-regex */ -import { Metadatum } from '../../Cardano'; import { InvalidStringError, OpaqueString } from '@cardano-sdk/util'; +import { Metadatum } from '../../Cardano'; export type Uri = OpaqueString<'Uri'>; export const Uri = (uri: string) => { diff --git a/packages/core/src/CML/address.ts b/packages/core/src/CML/address.ts index d6f84f30cfe..04832d4be96 100644 --- a/packages/core/src/CML/address.ts +++ b/packages/core/src/CML/address.ts @@ -1,4 +1,5 @@ -import { Address, Ed25519KeyHash, NetworkId, RewardAccount } from '../Cardano'; +import * as Crypto from '@cardano-sdk/crypto'; +import { Address, NetworkId, RewardAccount } from '../Cardano'; import { CML } from './CML'; import { parseCmlAddress } from './parseCmlAddress'; import { usingAutoFree } from '@cardano-sdk/util'; @@ -6,7 +7,7 @@ import { usingAutoFree } from '@cardano-sdk/util'; export const addressNetworkId = (address: RewardAccount | Address): NetworkId => usingAutoFree((scope) => parseCmlAddress(scope, address.toString())!.network_id()); -export const createRewardAccount = (stakeKeyHash: Ed25519KeyHash, networkId: NetworkId) => +export const createRewardAccount = (stakeKeyHash: Crypto.Ed25519KeyHashHex, networkId: NetworkId) => usingAutoFree((scope) => { const keyHash = scope.manage(CML.Ed25519KeyHash.from_hex(stakeKeyHash.toString())); const stakeCredential = scope.manage(CML.StakeCredential.from_keyhash(keyHash)); diff --git a/packages/core/src/CML/cmlToCore/certificate.ts b/packages/core/src/CML/cmlToCore/certificate.ts index 8bb0133bf4d..377f02cc7d7 100644 --- a/packages/core/src/CML/cmlToCore/certificate.ts +++ b/packages/core/src/CML/cmlToCore/certificate.ts @@ -1,8 +1,8 @@ +import * as Crypto from '@cardano-sdk/crypto'; import { CML } from '../CML'; import { Certificate, CertificateType, - Ed25519KeyHash, EpochNo, GenesisKeyDelegationCertificate, PoolId, @@ -15,14 +15,14 @@ import { StakeDelegationCertificate, VrfVkHex } from '../../Cardano/types'; -import { Hash28ByteBase16, Hash32ByteBase16, usingAutoFree } from '@cardano-sdk/util'; import { NetworkId } from '../../Cardano/ChainId'; import { NotImplementedError, SerializationError, SerializationFailure } from '../../errors'; +import { usingAutoFree } from '@cardano-sdk/util'; const stakeRegistration = (certificate: CML.StakeRegistration): StakeAddressCertificate => usingAutoFree((scope) => ({ __typename: CertificateType.StakeKeyRegistration, - stakeKeyHash: Ed25519KeyHash( + stakeKeyHash: Crypto.Ed25519KeyHashHex( Buffer.from(scope.manage(scope.manage(certificate.stake_credential()).to_keyhash())!.to_bytes()).toString('hex') ) })); @@ -30,7 +30,7 @@ const stakeRegistration = (certificate: CML.StakeRegistration): StakeAddressCert const stakeDeregistration = (certificate: CML.StakeDeregistration): StakeAddressCertificate => usingAutoFree((scope) => ({ __typename: CertificateType.StakeKeyDeregistration, - stakeKeyHash: Ed25519KeyHash( + stakeKeyHash: Crypto.Ed25519KeyHashHex( Buffer.from(scope.manage(scope.manage(certificate.stake_credential()).to_keyhash())!.to_bytes()).toString('hex') ) })); @@ -39,7 +39,7 @@ const stakeDelegation = (certificate: CML.StakeDelegation): StakeDelegationCerti usingAutoFree((scope) => ({ __typename: CertificateType.StakeDelegation, poolId: PoolId(scope.manage(certificate.pool_keyhash()).to_bech32('pool')), - stakeKeyHash: Ed25519KeyHash( + stakeKeyHash: Crypto.Ed25519KeyHashHex( Buffer.from(scope.manage(scope.manage(certificate.stake_credential()).to_keyhash())!.to_bytes()).toString('hex') ) })); @@ -97,7 +97,9 @@ const jsonMetadata = (poolMetadata?: CML.PoolMetadata): PoolMetadataJson | undef usingAutoFree((scope) => { if (!poolMetadata) return; return { - hash: Hash32ByteBase16(Buffer.from(scope.manage(poolMetadata.pool_metadata_hash()).to_bytes()).toString('hex')), + hash: Crypto.Hash32ByteBase16( + Buffer.from(scope.manage(poolMetadata.pool_metadata_hash()).to_bytes()).toString('hex') + ), url: scope.manage(poolMetadata.url()).url() }; }); @@ -135,9 +137,9 @@ const poolRetirement = (certificate: CML.PoolRetirement): PoolRetirementCertific const genesisKeyDelegation = (certificate: CML.GenesisKeyDelegation): GenesisKeyDelegationCertificate => usingAutoFree((scope) => ({ __typename: CertificateType.GenesisKeyDelegation, - genesisDelegateHash: Hash28ByteBase16(scope.manage(certificate.genesis_delegate_hash()).to_hex()), - genesisHash: Hash28ByteBase16(scope.manage(certificate.genesishash()).to_hex()), - vrfKeyHash: Hash32ByteBase16(scope.manage(certificate.vrf_keyhash()).to_hex()) + genesisDelegateHash: Crypto.Hash28ByteBase16(scope.manage(certificate.genesis_delegate_hash()).to_hex()), + genesisHash: Crypto.Hash28ByteBase16(scope.manage(certificate.genesishash()).to_hex()), + vrfKeyHash: Crypto.Hash32ByteBase16(scope.manage(certificate.vrf_keyhash()).to_hex()) })); export const createCertificate = (cmlCertificate: CML.Certificate): Certificate => diff --git a/packages/core/src/CML/cmlToCore/cmlToCore.ts b/packages/core/src/CML/cmlToCore/cmlToCore.ts index 72d8093cb76..bacef3bf8be 100644 --- a/packages/core/src/CML/cmlToCore/cmlToCore.ts +++ b/packages/core/src/CML/cmlToCore/cmlToCore.ts @@ -1,5 +1,6 @@ import * as Cardano from '../../Cardano'; -import { Base64Blob, Hash32ByteBase16, HexBlob, ManagedFreeableScope, usingAutoFree } from '@cardano-sdk/util'; +import * as Crypto from '@cardano-sdk/crypto'; +import { Base64Blob, HexBlob, ManagedFreeableScope, usingAutoFree } from '@cardano-sdk/util'; import { CML } from '../CML'; import { PlutusLanguageVersion, ScriptType } from '../../Cardano'; import { ScriptKind } from '@dcspark/cardano-multiplatform-lib-nodejs'; @@ -10,13 +11,13 @@ import { createCertificate } from './certificate'; export const txRequiredExtraSignatures = ( signatures: CML.Ed25519KeyHashes | undefined -): Cardano.Ed25519KeyHash[] | undefined => +): Crypto.Ed25519KeyHashHex[] | undefined => usingAutoFree((scope) => { if (!signatures) return; - const requiredSignatures: Cardano.Ed25519KeyHash[] = []; + const requiredSignatures: Crypto.Ed25519KeyHashHex[] = []; for (let i = 0; i < signatures.len(); i++) { const signature = scope.manage(signatures.get(i)); - const cardanoSignature = Cardano.Ed25519KeyHash(Buffer.from(signature.to_bytes()).toString('hex')); + const cardanoSignature = Crypto.Ed25519KeyHashHex(Buffer.from(signature.to_bytes()).toString('hex')); requiredSignatures.push(cardanoSignature); } return requiredSignatures; @@ -71,7 +72,7 @@ export const nativeScript = (script: CML.NativeScript): Cardano.NativeScript => case Cardano.NativeScriptKind.RequireSignature: { coreScript = { __type: Cardano.ScriptType.Native, - keyHash: Cardano.Ed25519KeyHash( + keyHash: Crypto.Ed25519KeyHashHex( bytesToHex(scope.manage(scope.manage(script.as_script_pubkey())!.addr_keyhash()).to_bytes()).toString() ), kind: Cardano.NativeScriptKind.RequireSignature @@ -188,7 +189,7 @@ export const txOut = (output: CML.TransactionOutput): Cardano.TxOut => return { address: Cardano.Address(address), datum: inlineDatum ? bytesToHex(inlineDatum) : undefined, - datumHash: dataHashBytes ? Hash32ByteBase16.fromHexBlob(bytesToHex(dataHashBytes)) : undefined, + datumHash: dataHashBytes ? Crypto.Hash32ByteBase16.fromHexBlob(bytesToHex(dataHashBytes)) : undefined, scriptReference: scriptRef ? getCoreScript(scope, scope.manage(scriptRef.script())) : undefined, value: value(scope.manage(output.amount())) }; @@ -281,7 +282,7 @@ export const txBody = (body: CML.TransactionBody): Cardano.TxBody => referenceInputs: cslReferenceInputs ? txInputs(cslReferenceInputs) : undefined, requiredExtraSignatures: txRequiredExtraSignatures(scope.manage(body.required_signers())), scriptIntegrityHash: - cslScriptDataHash && Hash32ByteBase16(Buffer.from(cslScriptDataHash.to_bytes()).toString('hex')), + cslScriptDataHash && Crypto.Hash32ByteBase16(Buffer.from(cslScriptDataHash.to_bytes()).toString('hex')), totalCollateral: cslTotalCollateral ? BigInt(cslTotalCollateral.to_str()) : undefined, validityInterval: validityInterval(scope, body), withdrawals: txWithdrawals(scope.manage(body.withdrawals())) @@ -299,10 +300,10 @@ export const txWitnessBootstrap = (bootstraps?: CML.BootstrapWitnesses): Cardano result.push({ addressAttributes: attributes?.length > 0 ? Base64Blob.fromBytes(attributes) : undefined, chainCode: chainCode?.length > 0 ? HexBlob.fromBytes(chainCode) : undefined, - key: Cardano.Ed25519PublicKey( + key: Crypto.Ed25519PublicKeyHex( Buffer.from(scope.manage(scope.manage(bootstrap.vkey()).public_key()).as_bytes()).toString('hex') ), - signature: Cardano.Ed25519Signature(scope.manage(bootstrap.signature()).to_hex()) + signature: Crypto.Ed25519SignatureHex(scope.manage(bootstrap.signature()).to_hex()) }); } return result; @@ -390,10 +391,10 @@ export const txWitnessSet = (witnessSet: CML.TransactionWitnessSet): Cardano.Wit for (let i = 0; i < vkeys!.len(); i++) { const witness = scope.manage(vkeys.get(i)); txSignatures.set( - Cardano.Ed25519PublicKey( + Crypto.Ed25519PublicKeyHex( Buffer.from(scope.manage(scope.manage(witness.vkey()).public_key()).as_bytes()).toString('hex') ), - Cardano.Ed25519Signature(scope.manage(witness.signature()).to_hex()) + Crypto.Ed25519SignatureHex(scope.manage(witness.signature()).to_hex()) ); } } diff --git a/packages/core/src/CML/coreToCml/certificate.ts b/packages/core/src/CML/coreToCml/certificate.ts index fcce31d277f..0103d3d57b5 100644 --- a/packages/core/src/CML/coreToCml/certificate.ts +++ b/packages/core/src/CML/coreToCml/certificate.ts @@ -1,4 +1,5 @@ import * as Cardano from '../../Cardano/types'; +import * as Crypto from '@cardano-sdk/crypto'; import { Address, BigNum, @@ -33,7 +34,7 @@ import { import { ManagedFreeableScope } from '@cardano-sdk/util'; import { NotImplementedError } from '../../errors'; -export const stakeKeyRegistration = (scope: ManagedFreeableScope, stakeKeyHash: Cardano.Ed25519KeyHash) => +export const stakeKeyRegistration = (scope: ManagedFreeableScope, stakeKeyHash: Crypto.Ed25519KeyHashHex) => scope.manage( Certificate.new_stake_registration( scope.manage( @@ -48,7 +49,7 @@ export const stakeKeyRegistration = (scope: ManagedFreeableScope, stakeKeyHash: ) ); -export const stakeKeyDeregistration = (scope: ManagedFreeableScope, stakeKeyHash: Cardano.Ed25519KeyHash) => +export const stakeKeyDeregistration = (scope: ManagedFreeableScope, stakeKeyHash: Crypto.Ed25519KeyHashHex) => scope.manage( Certificate.new_stake_deregistration( scope.manage( @@ -166,7 +167,7 @@ export const poolRetirement = (scope: ManagedFreeableScope, poolId: Cardano.Pool export const stakeDelegation = ( scope: ManagedFreeableScope, - stakeKeyHash: Cardano.Ed25519KeyHash, + stakeKeyHash: Crypto.Ed25519KeyHashHex, delegatee: Cardano.PoolId ) => scope.manage( diff --git a/packages/core/src/CML/coreToCml/coreToCml.ts b/packages/core/src/CML/coreToCml/coreToCml.ts index 3813bb6f507..2859edecb22 100644 --- a/packages/core/src/CML/coreToCml/coreToCml.ts +++ b/packages/core/src/CML/coreToCml/coreToCml.ts @@ -1,4 +1,5 @@ import * as Cardano from '../../Cardano'; +import * as Crypto from '@cardano-sdk/crypto'; import { AddrAttributes, Address, @@ -385,7 +386,7 @@ const txInputs = (scope: ManagedFreeableScope, coreInputs: Cardano.TxIn[]) => { return cslInputs; }; -const keyHashes = (scope: ManagedFreeableScope, coreHashes: Cardano.Ed25519KeyHash[]) => { +const keyHashes = (scope: ManagedFreeableScope, coreHashes: Crypto.Ed25519KeyHashHex[]) => { const cslKeyHashes = scope.manage(Ed25519KeyHashes.new()); for (const signature of coreHashes) { cslKeyHashes.add(scope.manage(Ed25519KeyHash.from_bytes(Buffer.from(signature, 'hex')))); diff --git a/packages/core/src/Cardano/types/Asset.ts b/packages/core/src/Cardano/types/Asset.ts index 99613990763..c54c935a286 100644 --- a/packages/core/src/Cardano/types/Asset.ts +++ b/packages/core/src/Cardano/types/Asset.ts @@ -1,5 +1,6 @@ import * as cip14 from '@emurgo/cip14-js'; -import { Hash28ByteBase16, InvalidStringError, OpaqueString, assertIsHexString, typedBech32 } from '@cardano-sdk/util'; +import { Hash28ByteBase16 } from '@cardano-sdk/crypto'; +import { InvalidStringError, OpaqueString, assertIsHexString, typedBech32 } from '@cardano-sdk/util'; export type AssetId = OpaqueString<'AssetId'>; diff --git a/packages/core/src/Cardano/types/AuxiliaryData.ts b/packages/core/src/Cardano/types/AuxiliaryData.ts index b0ce9e17fc3..79c5a4f71e9 100644 --- a/packages/core/src/Cardano/types/AuxiliaryData.ts +++ b/packages/core/src/Cardano/types/AuxiliaryData.ts @@ -1,4 +1,4 @@ -import { Hash32ByteBase16 } from '@cardano-sdk/util'; +import { Hash32ByteBase16 } from '@cardano-sdk/crypto'; import { Script } from './Script'; // eslint-disable-next-line no-use-before-define diff --git a/packages/core/src/Cardano/types/Block.ts b/packages/core/src/Cardano/types/Block.ts index 9a87d4e57a4..807637fbcab 100644 --- a/packages/core/src/Cardano/types/Block.ts +++ b/packages/core/src/Cardano/types/Block.ts @@ -1,13 +1,6 @@ +import * as Crypto from '@cardano-sdk/crypto'; import { CML } from '../../CML/CML'; -import { Ed25519PublicKey } from './Key'; -import { - Hash28ByteBase16, - Hash32ByteBase16, - InvalidStringError, - OpaqueNumber, - OpaqueString, - typedBech32 -} from '@cardano-sdk/util'; +import { InvalidStringError, OpaqueNumber, OpaqueString, typedBech32 } from '@cardano-sdk/util'; import { Lovelace } from './Value'; import { PoolId } from './StakePool/primitives'; import { Tx } from './Transaction'; @@ -54,7 +47,7 @@ export type Tip = PartialBlockHeader; * @param {string} value block hash as hex string * @throws InvalidStringError */ -export const BlockId = (value: string): BlockId => Hash32ByteBase16(value) as unknown as BlockId; +export const BlockId = (value: string): BlockId => Crypto.Hash32ByteBase16(value) as unknown as BlockId; /** * 32 byte ed25519 verification key as bech32 string. @@ -72,7 +65,7 @@ export const GenesisDelegate = (value: string): GenesisDelegate => { if (/ShelleyGenesis-[\da-f]{16}/.test(value)) { return value as unknown as GenesisDelegate; } - return Hash28ByteBase16(value) as unknown as GenesisDelegate; + return Crypto.Hash28ByteBase16(value) as unknown as GenesisDelegate; }; export type SlotLeader = PoolId | GenesisDelegate; @@ -114,7 +107,7 @@ export interface BlockInfo { * This is the operational cold verification key of the stake pool * Leaving as undefined for Byron blocks until we figure out how/if we can use the genesisKey field */ - issuerVk?: Ed25519PublicKey; + issuerVk?: Crypto.Ed25519PublicKeyHex; } export interface Block extends BlockInfo { diff --git a/packages/core/src/Cardano/types/Certificate.ts b/packages/core/src/Cardano/types/Certificate.ts index cbe413d8a15..bd48001278f 100644 --- a/packages/core/src/Cardano/types/Certificate.ts +++ b/packages/core/src/Cardano/types/Certificate.ts @@ -1,6 +1,5 @@ -import { Ed25519KeyHash } from './Key'; +import * as Crypto from '@cardano-sdk/crypto'; import { EpochNo } from './Block'; -import { Hash28ByteBase16, Hash32ByteBase16 } from '@cardano-sdk/util'; import { Lovelace } from './Value'; import { PoolId, PoolParameters } from './StakePool'; import { RewardAccount } from './RewardAccount'; @@ -17,7 +16,7 @@ export enum CertificateType { export interface StakeAddressCertificate { __typename: CertificateType.StakeKeyRegistration | CertificateType.StakeKeyDeregistration; - stakeKeyHash: Ed25519KeyHash; + stakeKeyHash: Crypto.Ed25519KeyHashHex; } export interface PoolRegistrationCertificate { @@ -33,7 +32,7 @@ export interface PoolRetirementCertificate { export interface StakeDelegationCertificate { __typename: CertificateType.StakeDelegation; - stakeKeyHash: Ed25519KeyHash; + stakeKeyHash: Crypto.Ed25519KeyHashHex; poolId: PoolId; } @@ -51,9 +50,9 @@ export interface MirCertificate { export interface GenesisKeyDelegationCertificate { __typename: CertificateType.GenesisKeyDelegation; - genesisHash: Hash28ByteBase16; - genesisDelegateHash: Hash28ByteBase16; - vrfKeyHash: Hash32ByteBase16; + genesisHash: Crypto.Hash28ByteBase16; + genesisDelegateHash: Crypto.Hash28ByteBase16; + vrfKeyHash: Crypto.Hash32ByteBase16; } export type Certificate = diff --git a/packages/core/src/Cardano/types/Key.ts b/packages/core/src/Cardano/types/Key.ts deleted file mode 100644 index c6de927763c..00000000000 --- a/packages/core/src/Cardano/types/Key.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { CML } from '../../CML/CML'; -import { Hash28ByteBase16, HexBlob, castHexBlob, typedHex } from '@cardano-sdk/util'; -import { OpaqueString, usingAutoFree } from '@cardano-sdk/util'; -import { RewardAccount } from './RewardAccount'; - -/** - * BIP32 public key as hex string - */ -export type Bip32PublicKey = OpaqueString<'Bip32PublicKey'>; -export const Bip32PublicKey = (key: string): Bip32PublicKey => typedHex(key, 128); -Bip32PublicKey.fromHexBlob = (value: HexBlob) => castHexBlob(value, 128); - -/** - * BIP32 private key as hex string - */ -export type Bip32PrivateKey = OpaqueString<'Bip32PrivateKey'>; -export const Bip32PrivateKey = (key: string): Bip32PrivateKey => typedHex(key, 192); -Bip32PrivateKey.fromHexBlob = (value: HexBlob) => castHexBlob(value, 192); - -/** - * Ed25519 public key as hex string - */ -export type Ed25519PublicKey = OpaqueString<'Ed25519PublicKey'>; - -/** - * @param {string} value Ed25519 public key as hex string - * @throws InvalidStringError - */ -export const Ed25519PublicKey = (value: string): Ed25519PublicKey => typedHex(value, 64); -Ed25519PublicKey.fromHexBlob = (value: HexBlob) => castHexBlob(value, 64); - -/** - * Ed25519 private key as hex string - */ -export type Ed25519PrivateKey = OpaqueString<'Ed25519PrivateKey'>; - -/** - * @param {string} value Ed25519 private key as hex string - * @throws InvalidStringError - */ -export const Ed25519PrivateKey = (value: string): Ed25519PrivateKey => typedHex(value, 128); -Ed25519PrivateKey.fromHexBlob = (value: HexBlob) => castHexBlob(value, 128); - -/** - * 28 byte ED25519 key hash as hex string - */ -export type Ed25519KeyHash = OpaqueString<'Ed25519KeyHash'>; -export const Ed25519KeyHash = (value: string): Ed25519KeyHash => Hash28ByteBase16(value) as unknown as Ed25519KeyHash; -Ed25519KeyHash.fromRewardAccount = (rewardAccount: RewardAccount): Ed25519KeyHash => - usingAutoFree((scope) => { - const bech32 = scope.manage(CML.Address.from_bech32(rewardAccount.toString())); - const rewardAddress = scope.manage(CML.RewardAddress.from_address(bech32)!); - const paymentCred = scope.manage(rewardAddress.payment_cred()!); - const keyHash = scope.manage(paymentCred.to_keyhash()!); - - return Ed25519KeyHash(Buffer.from(keyHash.to_bytes()).toString('hex')); - }); - -Ed25519KeyHash.fromKey = (pubKey: Ed25519PublicKey): Ed25519KeyHash => - usingAutoFree((scope) => { - const cmlPubKey = scope.manage(CML.PublicKey.from_bytes(Buffer.from(pubKey, 'hex'))); - const keyHash = scope.manage(cmlPubKey.hash()).to_bytes(); - - return Ed25519KeyHash(Buffer.from(keyHash!).toString('hex')); - }); diff --git a/packages/core/src/Cardano/types/RewardAccount.ts b/packages/core/src/Cardano/types/RewardAccount.ts index b7045a7f836..e020d70226c 100644 --- a/packages/core/src/Cardano/types/RewardAccount.ts +++ b/packages/core/src/Cardano/types/RewardAccount.ts @@ -1,4 +1,6 @@ -import { OpaqueString, typedBech32 } from '@cardano-sdk/util'; +import { CML } from '../../CML'; +import { Ed25519KeyHashHex } from '@cardano-sdk/crypto'; +import { OpaqueString, typedBech32, usingAutoFree } from '@cardano-sdk/util'; /** * mainnet or testnet stake address as bech32 string, @@ -11,3 +13,13 @@ export type RewardAccount = OpaqueString<'RewardAccount'>; * @throws InvalidStringError */ export const RewardAccount = (value: string): RewardAccount => typedBech32(value, ['stake', 'stake_test'], 47); + +RewardAccount.toHash = (rewardAccount: RewardAccount): Ed25519KeyHashHex => + usingAutoFree((scope) => { + const bech32 = scope.manage(CML.Address.from_bech32(rewardAccount.toString())); + const rewardAddress = scope.manage(CML.RewardAddress.from_address(bech32)!); + const paymentCred = scope.manage(rewardAddress.payment_cred()!); + const keyHash = scope.manage(paymentCred.to_keyhash()!); + + return Ed25519KeyHashHex(Buffer.from(keyHash.to_bytes()).toString('hex')); + }); diff --git a/packages/core/src/Cardano/types/Script.ts b/packages/core/src/Cardano/types/Script.ts index 7b29de78116..f672533a6d6 100644 --- a/packages/core/src/Cardano/types/Script.ts +++ b/packages/core/src/Cardano/types/Script.ts @@ -1,6 +1,6 @@ /* eslint-disable no-use-before-define */ -import { Ed25519KeyHash } from './Key'; -import { Hash32ByteBase16, HexBlob } from '@cardano-sdk/util'; +import * as Crypto from '@cardano-sdk/crypto'; +import { HexBlob } from '@cardano-sdk/util'; import { Slot } from './Block'; /** @@ -39,7 +39,7 @@ export interface RequireSignatureScript { /** * The hash of a verification key. */ - keyHash: Ed25519KeyHash; + keyHash: Crypto.Ed25519KeyHashHex; /** * The native script kind. @@ -211,7 +211,7 @@ export enum PlutusLanguageVersion { * this type of datum, the actual Datum value must be provided and will be added to the witness set of * the transaction. */ -export type DatumHash = Hash32ByteBase16; +export type DatumHash = Crypto.Hash32ByteBase16; /** * The datum is a piece of information that can be associated with a UTXO and is used to carry script state information diff --git a/packages/core/src/Cardano/types/StakePool/PoolParameters.ts b/packages/core/src/Cardano/types/StakePool/PoolParameters.ts index 944c99f6984..0d5c4626681 100644 --- a/packages/core/src/Cardano/types/StakePool/PoolParameters.ts +++ b/packages/core/src/Cardano/types/StakePool/PoolParameters.ts @@ -1,8 +1,8 @@ /* eslint-disable max-len */ import { ExtendedStakePoolMetadata } from './ExtendedStakePoolMetadata'; -import { Hash32ByteBase16, typedBech32 } from '@cardano-sdk/util'; +import { Hash32ByteBase16 } from '@cardano-sdk/crypto'; import { Lovelace } from '../Value'; -import { OpaqueString } from '@cardano-sdk/util'; +import { OpaqueString, typedBech32 } from '@cardano-sdk/util'; import { PoolId, VrfVkHex } from './primitives'; import { Relay } from './Relay'; import { RewardAccount } from '../RewardAccount'; diff --git a/packages/core/src/Cardano/types/StakePool/primitives.ts b/packages/core/src/Cardano/types/StakePool/primitives.ts index 3130151ec92..1ed3a5dee06 100644 --- a/packages/core/src/Cardano/types/StakePool/primitives.ts +++ b/packages/core/src/Cardano/types/StakePool/primitives.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -import { Ed25519KeyHash } from '../Key'; -import { Hash28ByteBase16, HexBlob, OpaqueString, typedBech32, typedHex } from '@cardano-sdk/util'; +import * as Crypto from '@cardano-sdk/crypto'; +import { HexBlob, OpaqueString, typedBech32, typedHex } from '@cardano-sdk/util'; /** * pool operator verification key hash as bech32 string or a genesis pool ID @@ -17,7 +17,8 @@ export const PoolId = (value: string): PoolId => typedBech32(value, 'pool', 45); * @param {string} value blake2b_224 digest of an operator verification key hash * @throws InvalidStringError */ -PoolId.fromKeyHash = (value: Ed25519KeyHash): PoolId => HexBlob.toTypedBech32('pool', value as unknown as HexBlob); +PoolId.fromKeyHash = (value: Crypto.Ed25519KeyHashHex): PoolId => + HexBlob.toTypedBech32('pool', HexBlob(value.toString())); /** /** @@ -29,7 +30,7 @@ export type PoolIdHex = OpaqueString<'PoolIdHex'>; * @param {string} value operator verification key hash as hex string * @throws InvalidStringError */ -export const PoolIdHex = (value: string): PoolIdHex => Hash28ByteBase16(value) as unknown as PoolIdHex; +export const PoolIdHex = (value: string): PoolIdHex => Crypto.Hash28ByteBase16(value) as unknown as PoolIdHex; /** * 32 byte VRF verification key as hex string diff --git a/packages/core/src/Cardano/types/Transaction.ts b/packages/core/src/Cardano/types/Transaction.ts index 3d4539616e5..e4c5ac099e1 100644 --- a/packages/core/src/Cardano/types/Transaction.ts +++ b/packages/core/src/Cardano/types/Transaction.ts @@ -1,9 +1,9 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ +import * as Crypto from '@cardano-sdk/crypto'; import { AuxiliaryData } from './AuxiliaryData'; -import { Base64Blob, Hash32ByteBase16, HexBlob, OpaqueString, typedHex } from '@cardano-sdk/util'; +import { Base64Blob, HexBlob, OpaqueString } from '@cardano-sdk/util'; import { Certificate } from './Certificate'; import { Datum, Script } from './Script'; -import { Ed25519KeyHash, Ed25519PublicKey } from './Key'; import { ExUnits, ValidityInterval } from './ProtocolParameters'; import { HydratedTxIn, TxIn, TxOut } from './Utxo'; import { Lovelace, TokenMap } from './Value'; @@ -19,19 +19,9 @@ export type TransactionId = OpaqueString<'TransactionId'>; * @param {string} value transaction hash as hex string * @throws InvalidStringError */ -export const TransactionId = (value: string): TransactionId => Hash32ByteBase16(value) as unknown as TransactionId; -TransactionId.fromHexBlob = (value: HexBlob) => Hash32ByteBase16.fromHexBlob(value); - -/** - * Ed25519 signature as hex string - */ -export type Ed25519Signature = OpaqueString<'Ed25519Signature'>; - -/** - * @param {string} value Ed25519 signature as hex string - * @throws InvalidStringError - */ -export const Ed25519Signature = (value: string): Ed25519Signature => typedHex(value, 128); +export const TransactionId = (value: string): TransactionId => + Crypto.Hash32ByteBase16(value) as unknown as TransactionId; +TransactionId.fromHexBlob = (value: HexBlob) => Crypto.Hash32ByteBase16.fromHexBlob(value); export interface Withdrawal { stakeAddress: RewardAccount; @@ -47,8 +37,8 @@ export interface HydratedTxBody { withdrawals?: Withdrawal[]; certificates?: Certificate[]; mint?: TokenMap; - scriptIntegrityHash?: Hash32ByteBase16; - requiredExtraSignatures?: Ed25519KeyHash[]; + scriptIntegrityHash?: Crypto.Hash32ByteBase16; + requiredExtraSignatures?: Crypto.Ed25519KeyHashHex[]; /** * The total collateral field lets users write transactions whose collateral is evident by just looking at the @@ -94,12 +84,12 @@ export interface Redeemer { executionUnits: ExUnits; } -export type Signatures = Map; +export type Signatures = Map; -export type Signature = Ed25519Signature; +export type Signature = Crypto.Ed25519SignatureHex; export type ChainCode = HexBlob; export type AddressAttributes = Base64Blob; -export type VerificationKey = Ed25519PublicKey; +export type VerificationKey = Crypto.Ed25519PublicKeyHex; export interface BootstrapWitness { signature: Signature; diff --git a/packages/core/src/Cardano/types/index.ts b/packages/core/src/Cardano/types/index.ts index ad85c497e29..4d77fed6a87 100644 --- a/packages/core/src/Cardano/types/index.ts +++ b/packages/core/src/Cardano/types/index.ts @@ -10,6 +10,5 @@ export * from './Genesis'; export * from './Block'; export * from './Asset'; export * from './AuxiliaryData'; -export * from './Key'; export * from './Script'; export * from './ProtocolParameters'; diff --git a/packages/core/src/tsconfig.json b/packages/core/src/tsconfig.json index cbd2721e548..2c3d1c92f19 100644 --- a/packages/core/src/tsconfig.json +++ b/packages/core/src/tsconfig.json @@ -6,6 +6,9 @@ "references": [ { "path": "../../util/src" + }, + { + "path": "../../crypto/src" } ] } diff --git a/packages/core/src/util/nativeScript.ts b/packages/core/src/util/nativeScript.ts index d0398d6e0ab..fd6c128bed0 100644 --- a/packages/core/src/util/nativeScript.ts +++ b/packages/core/src/util/nativeScript.ts @@ -1,5 +1,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import * as Cardano from '../Cardano'; +import * as Crypto from '@cardano-sdk/crypto'; import * as toCml from '../CML/coreToCml'; import { SerializationError, SerializationFailure } from '../'; import { usingAutoFree } from '@cardano-sdk/util'; @@ -35,7 +36,7 @@ export const jsonToNativeScript = (json: any): Cardano.NativeScript => { case 'sig': { coreScript = { __type: Cardano.ScriptType.Native, - keyHash: Cardano.Ed25519KeyHash(json.keyHash), + keyHash: Crypto.Ed25519KeyHashHex(json.keyHash), kind: Cardano.NativeScriptKind.RequireSignature }; diff --git a/packages/core/src/util/txInspector.ts b/packages/core/src/util/txInspector.ts index 254b6dfa700..7d5a0daa2c8 100644 --- a/packages/core/src/util/txInspector.ts +++ b/packages/core/src/util/txInspector.ts @@ -4,7 +4,6 @@ import { AssetName, Certificate, CertificateType, - Ed25519KeyHash, HydratedTx, HydratedTxIn, Lovelace, @@ -27,7 +26,6 @@ import { inputsWithAddresses, isAddressWithin } from '../Cardano/util/address'; import { nativeScriptPolicyId } from './nativeScript'; import { resolveInputValue } from '../Cardano/util/resolveInputValue'; import { subtractValueQuantities } from './subtractValueQuantities'; - type Inspector = (tx: HydratedTx) => Inspection; type Inspectors = { [k: string]: Inspector }; type TxInspector = (tx: HydratedTx) => { @@ -123,7 +121,7 @@ export const totalAddressOutputsValueInspector: SendReceiveValueInspector = (own export const signedCertificatesInspector: SignedCertificatesInspector = (rewardAccounts: RewardAccount[], certificateTypes?: CertificateType[]) => (tx) => { if (!tx.body.certificates || tx.body.certificates.length === 0) return []; - const stakeKeyHashes = rewardAccounts?.map((account) => Ed25519KeyHash.fromRewardAccount(account)); + const stakeKeyHashes = rewardAccounts?.map((account) => RewardAccount.toHash(account)); const certificates = certificateTypes ? tx.body.certificates?.filter((certificate) => certificateTypes.includes(certificate.__typename)) : tx.body.certificates; diff --git a/packages/core/test/CML/address.test.ts b/packages/core/test/CML/address.test.ts index 046ca88dcb9..e533c77188a 100644 --- a/packages/core/test/CML/address.test.ts +++ b/packages/core/test/CML/address.test.ts @@ -1,3 +1,4 @@ +import * as Crypto from '@cardano-sdk/crypto'; import { Cardano, addressNetworkId, createRewardAccount } from '../../src'; describe('address', () => { @@ -42,7 +43,7 @@ describe('address', () => { }); describe('createRewardAccount', () => { - const keyHash = Cardano.Ed25519KeyHash('f15db05f56035465bf8900a09bdaa16c3d8b8244fea686524408dd80'); + const keyHash = Crypto.Ed25519KeyHashHex('f15db05f56035465bf8900a09bdaa16c3d8b8244fea686524408dd80'); it('creates a mainnet address', () => { const rewardAccount = createRewardAccount(keyHash, Cardano.NetworkId.Mainnet); diff --git a/packages/core/test/CML/cmlToCore.test.ts b/packages/core/test/CML/cmlToCore.test.ts index 5054b5d5c78..23b78d26404 100644 --- a/packages/core/test/CML/cmlToCore.test.ts +++ b/packages/core/test/CML/cmlToCore.test.ts @@ -1,3 +1,4 @@ +import * as Crypto from '@cardano-sdk/crypto'; import { Base64Blob, HexBlob, ManagedFreeableScope } from '@cardano-sdk/util'; import { Cardano, cmlToCore, coreToCml } from '../../src'; import { NativeScript } from '@dcspark/cardano-multiplatform-lib-nodejs'; @@ -91,7 +92,7 @@ describe('cmlToCore', () => { scripts: [ { __type: Cardano.ScriptType.Native, - keyHash: Cardano.Ed25519KeyHash('b275b08c999097247f7c17e77007c7010cd19f20cc086ad99d398538'), + keyHash: Crypto.Ed25519KeyHashHex('b275b08c999097247f7c17e77007c7010cd19f20cc086ad99d398538'), kind: Cardano.NativeScriptKind.RequireSignature }, { @@ -105,7 +106,7 @@ describe('cmlToCore', () => { }, { __type: Cardano.ScriptType.Native, - keyHash: Cardano.Ed25519KeyHash('966e394a544f242081e41d1965137b1bb412ac230d40ed5407821c37'), + keyHash: Crypto.Ed25519KeyHashHex('966e394a544f242081e41d1965137b1bb412ac230d40ed5407821c37'), kind: Cardano.NativeScriptKind.RequireSignature }, { @@ -149,8 +150,8 @@ describe('cmlToCore', () => { { addressAttributes: Base64Blob('oA=='), chainCode: HexBlob('b6dbf0b03c93afe5696f10d49e8a8304ebfac01deeb8f82f2af5836ebbc1b450'), - key: Cardano.Ed25519PublicKey('deeb8f82f2af5836ebbc1b450b6dbf0b03c93afe5696f10d49e8a8304ebfac01'), - signature: Cardano.Ed25519Signature( + key: Crypto.Ed25519PublicKeyHex('deeb8f82f2af5836ebbc1b450b6dbf0b03c93afe5696f10d49e8a8304ebfac01'), + signature: Crypto.Ed25519SignatureHex( Buffer.from( 'ZGdic3hnZ3RvZ2hkanB0ZXR2dGtjb2N2eWZpZHFxZ2d1cmpocmhxYWlpc3BxcnVlbGh2eXBxeGVld3ByeWZ2dw==', 'base64' diff --git a/packages/core/test/CML/testData.ts b/packages/core/test/CML/testData.ts index e2ba67a8602..15a43593bb6 100644 --- a/packages/core/test/CML/testData.ts +++ b/packages/core/test/CML/testData.ts @@ -1,20 +1,14 @@ -import { Base64Blob, Hash28ByteBase16, Hash32ByteBase16, HexBlob } from '@cardano-sdk/util'; +import * as Crypto from '@cardano-sdk/crypto'; +import { Base64Blob, HexBlob } from '@cardano-sdk/util'; import { Cardano } from '../../src'; -import { - Ed25519KeyHash, - NativeScript, - NativeScriptKind, - PlutusLanguageVersion, - RedeemerPurpose, - ScriptType -} from '../../src/Cardano'; +import { NativeScript, NativeScriptKind, PlutusLanguageVersion, RedeemerPurpose, ScriptType } from '../../src/Cardano'; export const rewardAccount = Cardano.RewardAccount('stake1u89sasnfyjtmgk8ydqfv3fdl52f36x3djedfnzfc9rkgzrcss5vgr'); -export const stakeKeyHash = Ed25519KeyHash.fromRewardAccount(rewardAccount); +export const stakeKeyHash = Cardano.RewardAccount.toHash(rewardAccount); export const poolId = Cardano.PoolId('pool1mpgg03jxj52qwxvvy7cmj58a96vl9pvxcqqvuw0kumheygxmn34'); export const ownerRewardAccount = Cardano.RewardAccount('stake1u89sasnfyjtmgk8ydqfv3fdl52f36x3djedfnzfc9rkgzrcss5vgr'); export const vrf = Cardano.VrfVkHex('8dd154228946bd12967c12bedb1cb6038b78f8b84a1760b1a788fa72a4af3db0'); export const metadataJson = { - hash: Hash32ByteBase16('0f3abbc8fc19c2e61bab6059bf8a466e6e754833a08a62a6c56fe0e78f19d9d5'), + hash: Crypto.Hash32ByteBase16('0f3abbc8fc19c2e61bab6059bf8a466e6e754833a08a62a6c56fe0e78f19d9d5'), url: 'https://example.com' }; export const poolParameters: Cardano.PoolParameters = { @@ -43,7 +37,7 @@ export const script: NativeScript = { scripts: [ { __type: ScriptType.Native, - keyHash: Ed25519KeyHash('b275b08c999097247f7c17e77007c7010cd19f20cc086ad99d398538'), + keyHash: Crypto.Ed25519KeyHashHex('b275b08c999097247f7c17e77007c7010cd19f20cc086ad99d398538'), kind: NativeScriptKind.RequireSignature }, { @@ -57,7 +51,7 @@ export const script: NativeScript = { }, { __type: ScriptType.Native, - keyHash: Ed25519KeyHash('966e394a544f242081e41d1965137b1bb412ac230d40ed5407821c37'), + keyHash: Crypto.Ed25519KeyHashHex('966e394a544f242081e41d1965137b1bb412ac230d40ed5407821c37'), kind: NativeScriptKind.RequireSignature }, { @@ -112,7 +106,7 @@ export const invalidBabbageTxOut: Cardano.TxOut = { 'addr_test1qz2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer3jcu5d8ps7zex2k2xt3uqxgjqnnj83ws8lhrn648jjxtwq2ytjqp' ), datum: HexBlob('187b'), - datumHash: Hash32ByteBase16('0f3abbc8fc19c2e61bab6059bf8a466e6e754833a08a62a6c56fe0e78f19d9d5'), + datumHash: Crypto.Hash32ByteBase16('0f3abbc8fc19c2e61bab6059bf8a466e6e754833a08a62a6c56fe0e78f19d9d5'), scriptReference: script, value: valueWithAssets }; @@ -121,7 +115,7 @@ export const babbageTxOutWithDatumHash: Cardano.TxOut = { address: Cardano.Address( 'addr_test1qz2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer3jcu5d8ps7zex2k2xt3uqxgjqnnj83ws8lhrn648jjxtwq2ytjqp' ), - datumHash: Hash32ByteBase16('0f3abbc8fc19c2e61bab6059bf8a466e6e754833a08a62a6c56fe0e78f19d9d5'), + datumHash: Crypto.Hash32ByteBase16('0f3abbc8fc19c2e61bab6059bf8a466e6e754833a08a62a6c56fe0e78f19d9d5'), scriptReference: script, value: valueWithAssets }; @@ -144,7 +138,7 @@ export const txOutWithDatum: Cardano.TxOut = { address: Cardano.Address( 'addr_test1qz2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer3jcu5d8ps7zex2k2xt3uqxgjqnnj83ws8lhrn648jjxtwq2ytjqp' ), - datumHash: Hash32ByteBase16('4c94610a582b748b8db506abb45ccd48d0d4934942daa87d191645b947a547a7'), + datumHash: Crypto.Hash32ByteBase16('4c94610a582b748b8db506abb45ccd48d0d4934942daa87d191645b947a547a7'), value: valueWithAssets }; @@ -157,9 +151,9 @@ export const txBody: Cardano.TxBody = { }, { __typename: Cardano.CertificateType.GenesisKeyDelegation, - genesisDelegateHash: Hash28ByteBase16('a646474b8f5431261506b6c273d307c7569a4eb6c96b42dd4a29520a'), - genesisHash: Hash28ByteBase16('0d94e174732ef9aae73f395ab44507bfa983d65023c11a951f0c32e4'), - vrfKeyHash: Hash32ByteBase16('03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314') + genesisDelegateHash: Crypto.Hash28ByteBase16('a646474b8f5431261506b6c273d307c7569a4eb6c96b42dd4a29520a'), + genesisHash: Crypto.Hash28ByteBase16('0d94e174732ef9aae73f395ab44507bfa983d65023c11a951f0c32e4'), + vrfKeyHash: Crypto.Hash32ByteBase16('03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314') } ], collaterals: [{ ...txIn, index: txIn.index + 1 }], @@ -167,8 +161,8 @@ export const txBody: Cardano.TxBody = { inputs: [txIn], mint: mintTokenMap, outputs: [txOut], - requiredExtraSignatures: [Cardano.Ed25519KeyHash('6199186adb51974690d7247d2646097d2c62763b16fb7ed3f9f55d39')], - scriptIntegrityHash: Hash32ByteBase16('6199186adb51974690d7247d2646097d2c62763b16fb7ed3f9f55d38abc123de'), + requiredExtraSignatures: [Crypto.Ed25519KeyHashHex('6199186adb51974690d7247d2646097d2c62763b16fb7ed3f9f55d39')], + scriptIntegrityHash: Crypto.Hash32ByteBase16('6199186adb51974690d7247d2646097d2c62763b16fb7ed3f9f55d38abc123de'), validityInterval: { invalidBefore: Cardano.Slot(100), invalidHereafter: Cardano.Slot(1000) @@ -219,8 +213,8 @@ export const tx: Cardano.Tx = { { addressAttributes: Base64Blob('oA=='), chainCode: HexBlob('b6dbf0b03c93afe5696f10d49e8a8304ebfac01deeb8f82f2af5836ebbc1b450'), - key: Cardano.Ed25519PublicKey('deeb8f82f2af5836ebbc1b450b6dbf0b03c93afe5696f10d49e8a8304ebfac01'), - signature: Cardano.Ed25519Signature( + key: Crypto.Ed25519PublicKeyHex('deeb8f82f2af5836ebbc1b450b6dbf0b03c93afe5696f10d49e8a8304ebfac01'), + signature: Crypto.Ed25519SignatureHex( Buffer.from( 'ZGdic3hnZ3RvZ2hkanB0ZXR2dGtjb2N2eWZpZHFxZ2d1cmpocmhxYWlpc3BxcnVlbGh2eXBxeGVld3ByeWZ2dw==', 'base64' @@ -272,7 +266,7 @@ export const tx: Cardano.Tx = { }, { __type: ScriptType.Native, - keyHash: Cardano.Ed25519KeyHash('b5ae663aaea8e500157bdf4baafd6f5ba0ce5759f7cd4101fc132f54'), + keyHash: Crypto.Ed25519KeyHashHex('b5ae663aaea8e500157bdf4baafd6f5ba0ce5759f7cd4101fc132f54'), kind: NativeScriptKind.RequireSignature }, { @@ -281,7 +275,7 @@ export const tx: Cardano.Tx = { scripts: [ { __type: ScriptType.Native, - keyHash: Cardano.Ed25519KeyHash('b5ae663aaea8e500157bdf4baafd6f5ba0ce5759f7cd4101fc132f54'), + keyHash: Crypto.Ed25519KeyHashHex('b5ae663aaea8e500157bdf4baafd6f5ba0ce5759f7cd4101fc132f54'), kind: NativeScriptKind.RequireSignature } ] @@ -292,7 +286,7 @@ export const tx: Cardano.Tx = { scripts: [ { __type: ScriptType.Native, - keyHash: Cardano.Ed25519KeyHash('b5ae663aaea8e500157bdf4baafd6f5ba0ce5759f7cd4101fc132f54'), + keyHash: Crypto.Ed25519KeyHashHex('b5ae663aaea8e500157bdf4baafd6f5ba0ce5759f7cd4101fc132f54'), kind: NativeScriptKind.RequireSignature } ] @@ -304,13 +298,13 @@ export const tx: Cardano.Tx = { scripts: [ { __type: ScriptType.Native, - keyHash: Cardano.Ed25519KeyHash('b5ae663aaea8e500157bdf4baafd6f5ba0ce5759f7cd4101fc132f54'), + keyHash: Crypto.Ed25519KeyHashHex('b5ae663aaea8e500157bdf4baafd6f5ba0ce5759f7cd4101fc132f54'), kind: NativeScriptKind.RequireSignature } ] } ], - signatures: new Map([[Cardano.Ed25519PublicKey(vkey), Cardano.Ed25519Signature(signature)]]) + signatures: new Map([[Crypto.Ed25519PublicKeyHex(vkey), Crypto.Ed25519SignatureHex(signature)]]) } }; diff --git a/packages/core/test/Cardano/types/Asset.test.ts b/packages/core/test/Cardano/types/Asset.test.ts index 55138cedf5f..cafaa9df294 100644 --- a/packages/core/test/Cardano/types/Asset.test.ts +++ b/packages/core/test/Cardano/types/Asset.test.ts @@ -1,16 +1,24 @@ import { AssetFingerprint, AssetId, AssetName, PolicyId } from '../../../src/Cardano'; -import { Hash28ByteBase16, assertIsHexString, typedBech32 } from '@cardano-sdk/util'; +import { Hash28ByteBase16 } from '@cardano-sdk/crypto'; +import { assertIsHexString, typedBech32 } from '@cardano-sdk/util'; jest.mock('@cardano-sdk/util', () => { const actual = jest.requireActual('@cardano-sdk/util'); return { ...actual, - Hash28ByteBase16: jest.fn().mockImplementation((...args) => actual.Hash28ByteBase16(...args)), assertIsHexString: jest.fn().mockImplementation((...args) => actual.assertIsHexString(...args)), typedBech32: jest.fn().mockImplementation((...args) => actual.typedBech32(...args)) }; }); +jest.mock('@cardano-sdk/crypto', () => { + const actual = jest.requireActual('@cardano-sdk/crypto'); + return { + ...actual, + Hash28ByteBase16: jest.fn().mockImplementation((...args) => actual.Hash28ByteBase16(...args)) + }; +}); + describe('Cardano/types/Asset', () => { describe('AssetId', () => { it('accepts a valid asset id and is implemented using util.assetIsHexString', () => { diff --git a/packages/core/test/Cardano/types/Block.test.ts b/packages/core/test/Cardano/types/Block.test.ts index f32642475a1..99816c00571 100644 --- a/packages/core/test/Cardano/types/Block.test.ts +++ b/packages/core/test/Cardano/types/Block.test.ts @@ -1,16 +1,24 @@ import { BlockId, SlotLeader, VrfVkBech32 } from '../../../src/Cardano'; -import { Hash32ByteBase16, InvalidStringError, typedBech32 } from '@cardano-sdk/util'; +import { Hash32ByteBase16 } from '@cardano-sdk/crypto'; +import { InvalidStringError, typedBech32 } from '@cardano-sdk/util'; jest.mock('@cardano-sdk/util', () => { const actual = jest.requireActual('@cardano-sdk/util'); return { ...actual, - Hash28ByteBase16: jest.fn().mockImplementation((...args) => actual.Hash28ByteBase16(...args)), - Hash32ByteBase16: jest.fn().mockImplementation((...args) => actual.Hash32ByteBase16(...args)), typedBech32: jest.fn().mockImplementation((...args) => actual.typedBech32(...args)) }; }); +jest.mock('@cardano-sdk/crypto', () => { + const actual = jest.requireActual('@cardano-sdk/crypto'); + return { + ...actual, + Hash28ByteBase16: jest.fn().mockImplementation((...args) => actual.Hash28ByteBase16(...args)), + Hash32ByteBase16: jest.fn().mockImplementation((...args) => actual.Hash32ByteBase16(...args)) + }; +}); + describe('Cardano/types/Block', () => { it('BlockId() accepts a valid transaction hash and is implemented using Hash32ByteBase16', () => { expect(() => BlockId('0dbe461fb5f981c0d01615332b8666340eb1a692b3034f46bcb5f5ea4172b2ed')).not.toThrow(); diff --git a/packages/core/test/Cardano/types/Key.test.ts b/packages/core/test/Cardano/types/Key.test.ts deleted file mode 100644 index f8a69eb6d98..00000000000 --- a/packages/core/test/Cardano/types/Key.test.ts +++ /dev/null @@ -1,86 +0,0 @@ -/* eslint-disable max-len */ -import { CML, Cardano } from '../../../src'; -import { Ed25519KeyHash } from '../../../src/Cardano'; -import { HexBlob } from '@cardano-sdk/util'; - -describe('Cardano/types/Key', () => { - it('Ed25519PublicKey() accepts a valid public key hex string', () => { - expect(() => - Cardano.Ed25519PublicKey('6199186adb51974690d7247d2646097d2c62763b767b528816fb7ed3f9f55d39') - ).not.toThrow(); - expect(() => - Cardano.Ed25519PublicKey.fromHexBlob(HexBlob('6199186adb51974690d7247d2646097d2c62763b767b528816fb7ed3f9f55d39')) - ).not.toThrow(); - }); - - it('Ed25519PrivateKey() accepts a valid private key hex string', () => { - expect(() => - Cardano.Ed25519PrivateKey( - '6199186adb51974690d7247d2646097d2c62763b767b528816fb7ed3f9f55d396199186adb51974690d7247d2646097d2c62763b767b528816fb7ed3f9f55d39' - ) - ).not.toThrow(); - expect(() => - Cardano.Ed25519PrivateKey.fromHexBlob( - HexBlob( - '6199186adb51974690d7247d2646097d2c62763b767b528816fb7ed3f9f55d396199186adb51974690d7247d2646097d2c62763b767b528816fb7ed3f9f55d39' - ) - ) - ).not.toThrow(); - }); - - describe('Ed25519KeyHash', () => { - it('accepts a key hash hex string', () => { - expect(() => Cardano.Ed25519KeyHash('6199186adb51974690d7247d2646097d2c62763b767b528816fb7ed5')).not.toThrow(); - }); - - it('is of same length as in CSL', () => { - expect(() => - CML.Ed25519KeyHash.from_bytes( - Buffer.from(Cardano.Ed25519KeyHash('6199186adb51974690d7247d2646097d2c62763b767b528816fb7ed5'), 'hex') - ) - ).not.toThrow(); - }); - - test('fromRewardAccount', () => { - const rewardAccount = Cardano.RewardAccount('stake1u89sasnfyjtmgk8ydqfv3fdl52f36x3djedfnzfc9rkgzrcss5vgr'); - expect(Ed25519KeyHash.fromRewardAccount(rewardAccount)).toEqual( - 'cb0ec2692497b458e46812c8a5bfa2931d1a2d965a99893828ec810f' - ); - }); - - test('fromKey', () => { - const pubKey = Cardano.Ed25519PublicKey('6f48ffce45af1722cd7f641d624cd36671a0777c15ff78f016779177a48f7ba2'); - expect(Ed25519KeyHash.fromKey(pubKey)).toEqual('6f233080cebdc47e520885876caea84bdb02ba67bcea95ed890b22e6'); - }); - }); - - it('Bip32PublicKey() accepts a valid public key hex string', () => { - expect(() => - Cardano.Bip32PublicKey( - '6199186adb51974690d7247d2646097d2c62763b767b528816fb7ed3f9f55d396199186adb51974690d7247d2646097d2c62763b767b528816fb7ed3f9f55d39' - ) - ).not.toThrow(); - expect(() => - Cardano.Bip32PublicKey.fromHexBlob( - HexBlob( - '6199186adb51974690d7247d2646097d2c62763b767b528816fb7ed3f9f55d396199186adb51974690d7247d2646097d2c62763b767b528816fb7ed3f9f55d39' - ) - ) - ).not.toThrow(); - }); - - it('Bip32PrivateKey() accepts a valid public key hex string', () => { - expect(() => - Cardano.Bip32PrivateKey( - '6199186adb51974690d7247d2646097d2c62763b767b528816fb7ed3f9f55d36199186adb51974690d7247d2646097d2c62763b767b528816fb7ed3f9f55d3996199186adb51974690d7247d2646097d2c62763b767b528816fb7ed3f9f55d39' - ) - ).not.toThrow(); - expect(() => - Cardano.Bip32PrivateKey.fromHexBlob( - HexBlob( - '6199186adb51974690d7247d2646097d2c62763b767b528816fb7ed3f9f55d36199186adb51974690d7247d2646097d2c62763b767b528816fb7ed3f9f55d3996199186adb51974690d7247d2646097d2c62763b767b528816fb7ed3f9f55d39' - ) - ) - ).not.toThrow(); - }); -}); diff --git a/packages/core/test/Cardano/types/StakePool.test.ts b/packages/core/test/Cardano/types/StakePool.test.ts index d09813fdd07..8b53324458e 100644 --- a/packages/core/test/Cardano/types/StakePool.test.ts +++ b/packages/core/test/Cardano/types/StakePool.test.ts @@ -1,3 +1,4 @@ +import * as Crypto from '@cardano-sdk/crypto'; import { Cardano } from '../../../src'; describe('Cardano/types/StakePool', () => { @@ -7,7 +8,7 @@ describe('Cardano/types/StakePool', () => { it('PoolId.fromKeyHash() returns valid pool id encoded as a bech32 string', () => { const poolId = Cardano.PoolId.fromKeyHash( - Cardano.Ed25519KeyHash('594df1c896f6b05d4bebec0287627cf83416db779a3273205d3db9e0') + Crypto.Ed25519KeyHashHex('594df1c896f6b05d4bebec0287627cf83416db779a3273205d3db9e0') ); expect(poolId).toEqual(Cardano.PoolId('pool1t9xlrjyk76c96jltaspgwcnulq6pdkmhnge8xgza8ku7qvpsy9r')); }); diff --git a/packages/core/test/Cardano/types/Transaction.test.ts b/packages/core/test/Cardano/types/Transaction.test.ts index 90620428e6b..c5b74682893 100644 --- a/packages/core/test/Cardano/types/Transaction.test.ts +++ b/packages/core/test/Cardano/types/Transaction.test.ts @@ -1,17 +1,20 @@ -import { Ed25519Signature, TransactionId } from '../../../src/Cardano'; +import { Cardano } from '../../../'; +import { Ed25519SignatureHex } from '@cardano-sdk/crypto'; import { HexBlob } from '@cardano-sdk/util'; describe('Cardano/types/Transaction', () => { it('TransactionId accepts a valid transaction hash hex string', () => { - expect(() => TransactionId('3e33018e8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d')).not.toThrow(); expect(() => - TransactionId.fromHexBlob(HexBlob('3e33018e8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d')) + Cardano.TransactionId('3e33018e8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d') + ).not.toThrow(); + expect(() => + Cardano.TransactionId.fromHexBlob(HexBlob('3e33018e8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d')) ).not.toThrow(); }); it('Ed25519Signature() accepts a valid signature hex string', () => { expect(() => - Ed25519Signature( + Ed25519SignatureHex( // eslint-disable-next-line max-len '709f937c4ce152c81f8406c03279ff5a8556a12a8657e40a578eaaa6223d2e6a2fece39733429e3ec73a6c798561b5c2d47d82224d656b1d964cfe8b5fdffe09' ) diff --git a/packages/core/test/Cardano/util/computeImplicitCoin.test.ts b/packages/core/test/Cardano/util/computeImplicitCoin.test.ts index f58c0532752..f534a7c48e5 100644 --- a/packages/core/test/Cardano/util/computeImplicitCoin.test.ts +++ b/packages/core/test/Cardano/util/computeImplicitCoin.test.ts @@ -4,7 +4,7 @@ describe('Cardano.util.computeImplicitCoin', () => { it('sums registrations for deposit, withdrawals and deregistrations for input', async () => { const protocolParameters = { poolDeposit: 3, stakeKeyDeposit: 2 } as Cardano.ProtocolParameters; const rewardAccount = Cardano.RewardAccount('stake_test1uqfu74w3wh4gfzu8m6e7j987h4lq9r3t7ef5gaw497uu85qsqfy27'); - const stakeKeyHash = Cardano.Ed25519KeyHash.fromRewardAccount(rewardAccount); + const stakeKeyHash = Cardano.RewardAccount.toHash(rewardAccount); const certificates: Cardano.Certificate[] = [ { __typename: Cardano.CertificateType.StakeKeyRegistration, stakeKeyHash }, { __typename: Cardano.CertificateType.StakeKeyDeregistration, stakeKeyHash }, diff --git a/packages/core/test/tsconfig.json b/packages/core/test/tsconfig.json index e1f98935481..4436ddb1590 100644 --- a/packages/core/test/tsconfig.json +++ b/packages/core/test/tsconfig.json @@ -9,6 +9,9 @@ }, { "path": "../../util-dev/src" + }, + { + "path": "../../crypto/src" } ] } diff --git a/packages/core/test/util/nativeScript.test.ts b/packages/core/test/util/nativeScript.test.ts index 7c8b6acb5e6..e2c67403b1a 100644 --- a/packages/core/test/util/nativeScript.test.ts +++ b/packages/core/test/util/nativeScript.test.ts @@ -1,5 +1,6 @@ import * as Cardano from '../../src/Cardano'; -import { Ed25519KeyHash, NativeScript, NativeScriptKind, ScriptType, Slot } from '../../src/Cardano'; +import { Ed25519KeyHashHex } from '@cardano-sdk/crypto'; +import { NativeScript, NativeScriptKind, ScriptType, Slot } from '../../src/Cardano'; import { jsonToNativeScript, nativeScriptPolicyId } from '../../src'; describe('nativeScript utils', () => { @@ -10,7 +11,7 @@ describe('nativeScript utils', () => { scripts: [ { __type: ScriptType.Native, - keyHash: Ed25519KeyHash('b275b08c999097247f7c17e77007c7010cd19f20cc086ad99d398538'), + keyHash: Ed25519KeyHashHex('b275b08c999097247f7c17e77007c7010cd19f20cc086ad99d398538'), kind: NativeScriptKind.RequireSignature }, { @@ -24,7 +25,7 @@ describe('nativeScript utils', () => { }, { __type: ScriptType.Native, - keyHash: Ed25519KeyHash('966e394a544f242081e41d1965137b1bb412ac230d40ed5407821c37'), + keyHash: Ed25519KeyHashHex('966e394a544f242081e41d1965137b1bb412ac230d40ed5407821c37'), kind: NativeScriptKind.RequireSignature }, { @@ -48,7 +49,7 @@ describe('nativeScript utils', () => { const expectedScript: NativeScript = { __type: Cardano.ScriptType.Native, - keyHash: Cardano.Ed25519KeyHash('e09d36c79dec9bd1b3d9e152247701cd0bb860b5ebfd1de8abb6735a'), + keyHash: Ed25519KeyHashHex('e09d36c79dec9bd1b3d9e152247701cd0bb860b5ebfd1de8abb6735a'), kind: Cardano.NativeScriptKind.RequireSignature }; @@ -85,17 +86,17 @@ describe('nativeScript utils', () => { scripts: [ { __type: Cardano.ScriptType.Native, - keyHash: Cardano.Ed25519KeyHash('e09d36c79dec9bd1b3d9e152247701cd0bb860b5ebfd1de8abb6735a'), + keyHash: Ed25519KeyHashHex('e09d36c79dec9bd1b3d9e152247701cd0bb860b5ebfd1de8abb6735a'), kind: Cardano.NativeScriptKind.RequireSignature }, { __type: Cardano.ScriptType.Native, - keyHash: Cardano.Ed25519KeyHash('a687dcc24e00dd3caafbeb5e68f97ca8ef269cb6fe971345eb951756'), + keyHash: Ed25519KeyHashHex('a687dcc24e00dd3caafbeb5e68f97ca8ef269cb6fe971345eb951756'), kind: Cardano.NativeScriptKind.RequireSignature }, { __type: Cardano.ScriptType.Native, - keyHash: Cardano.Ed25519KeyHash('0bd1d702b2e6188fe0857a6dc7ffb0675229bab58c86638ffa87ed6d'), + keyHash: Ed25519KeyHashHex('0bd1d702b2e6188fe0857a6dc7ffb0675229bab58c86638ffa87ed6d'), kind: Cardano.NativeScriptKind.RequireSignature } ] @@ -133,17 +134,17 @@ describe('nativeScript utils', () => { scripts: [ { __type: Cardano.ScriptType.Native, - keyHash: Cardano.Ed25519KeyHash('e09d36c79dec9bd1b3d9e152247701cd0bb860b5ebfd1de8abb6735a'), + keyHash: Ed25519KeyHashHex('e09d36c79dec9bd1b3d9e152247701cd0bb860b5ebfd1de8abb6735a'), kind: Cardano.NativeScriptKind.RequireSignature }, { __type: Cardano.ScriptType.Native, - keyHash: Cardano.Ed25519KeyHash('a687dcc24e00dd3caafbeb5e68f97ca8ef269cb6fe971345eb951756'), + keyHash: Ed25519KeyHashHex('a687dcc24e00dd3caafbeb5e68f97ca8ef269cb6fe971345eb951756'), kind: Cardano.NativeScriptKind.RequireSignature }, { __type: Cardano.ScriptType.Native, - keyHash: Cardano.Ed25519KeyHash('0bd1d702b2e6188fe0857a6dc7ffb0675229bab58c86638ffa87ed6d'), + keyHash: Ed25519KeyHashHex('0bd1d702b2e6188fe0857a6dc7ffb0675229bab58c86638ffa87ed6d'), kind: Cardano.NativeScriptKind.RequireSignature } ] @@ -183,17 +184,17 @@ describe('nativeScript utils', () => { scripts: [ { __type: Cardano.ScriptType.Native, - keyHash: Cardano.Ed25519KeyHash('e09d36c79dec9bd1b3d9e152247701cd0bb860b5ebfd1de8abb6735a'), + keyHash: Ed25519KeyHashHex('e09d36c79dec9bd1b3d9e152247701cd0bb860b5ebfd1de8abb6735a'), kind: Cardano.NativeScriptKind.RequireSignature }, { __type: Cardano.ScriptType.Native, - keyHash: Cardano.Ed25519KeyHash('a687dcc24e00dd3caafbeb5e68f97ca8ef269cb6fe971345eb951756'), + keyHash: Ed25519KeyHashHex('a687dcc24e00dd3caafbeb5e68f97ca8ef269cb6fe971345eb951756'), kind: Cardano.NativeScriptKind.RequireSignature }, { __type: Cardano.ScriptType.Native, - keyHash: Cardano.Ed25519KeyHash('0bd1d702b2e6188fe0857a6dc7ffb0675229bab58c86638ffa87ed6d'), + keyHash: Ed25519KeyHashHex('0bd1d702b2e6188fe0857a6dc7ffb0675229bab58c86638ffa87ed6d'), kind: Cardano.NativeScriptKind.RequireSignature } ] @@ -232,7 +233,7 @@ describe('nativeScript utils', () => { }, { __type: Cardano.ScriptType.Native, - keyHash: Cardano.Ed25519KeyHash('966e394a544f242081e41d1965137b1bb412ac230d40ed5407821c37'), + keyHash: Ed25519KeyHashHex('966e394a544f242081e41d1965137b1bb412ac230d40ed5407821c37'), kind: Cardano.NativeScriptKind.RequireSignature } ] @@ -271,7 +272,7 @@ describe('nativeScript utils', () => { }, { __type: Cardano.ScriptType.Native, - keyHash: Cardano.Ed25519KeyHash('966e394a544f242081e41d1965137b1bb412ac230d40ed5407821c37'), + keyHash: Ed25519KeyHashHex('966e394a544f242081e41d1965137b1bb412ac230d40ed5407821c37'), kind: Cardano.NativeScriptKind.RequireSignature } ] diff --git a/packages/core/test/util/txInspector.test.ts b/packages/core/test/util/txInspector.test.ts index 10eaba39af9..05c94a88861 100644 --- a/packages/core/test/util/txInspector.test.ts +++ b/packages/core/test/util/txInspector.test.ts @@ -8,9 +8,6 @@ import { BlockNo, Certificate, CertificateType, - Ed25519KeyHash, - Ed25519PublicKey, - Ed25519Signature, EpochNo, HydratedTx, HydratedTxIn, @@ -31,7 +28,7 @@ import { Withdrawal, Witness } from '../../src/Cardano'; -import { Hash32ByteBase16 } from '@cardano-sdk/util'; +import { Ed25519KeyHashHex, Ed25519PublicKeyHex, Ed25519SignatureHex, Hash32ByteBase16 } from '@cardano-sdk/crypto'; import { assetsBurnedInspector, assetsMintedInspector, @@ -61,7 +58,7 @@ describe('txInspector', () => { 'addr_test1qpfhhfy2qgls50r9u4yh0l7z67xpg0a5rrhkmvzcuqrd0znuzcjqw982pcftgx53fu5527z2cj2tkx2h8ux2vxsg475q9gw0lz' ); const rewardAccount = RewardAccount('stake_test1up7pvfq8zn4quy45r2g572290p9vf99mr9tn7r9xrgy2l2qdsf58d'); - const stakeKeyHash = Ed25519KeyHash.fromRewardAccount(rewardAccount); + const stakeKeyHash = RewardAccount.toHash(rewardAccount); const poolId = PoolId('pool1euf2nh92ehqfw7rpd4s9qgq34z8dg4pvfqhjmhggmzk95gcd402'); const delegationCert: StakeDelegationCertificate = { __typename: CertificateType.StakeDelegation, @@ -174,7 +171,7 @@ describe('txInspector', () => { scripts: [ { __type: ScriptType.Native, - keyHash: Ed25519KeyHash('24accb6ca2690388f067175d773871f5640de57bf11aec0be258d6c7'), + keyHash: Ed25519KeyHashHex('24accb6ca2690388f067175d773871f5640de57bf11aec0be258d6c7'), kind: NativeScriptKind.RequireSignature } ] @@ -186,7 +183,7 @@ describe('txInspector', () => { scripts: [ { __type: ScriptType.Native, - keyHash: Ed25519KeyHash('00accb6ca2690388f067175d773871f5640de57bf11aec0be258d6c7'), + keyHash: Ed25519KeyHashHex('00accb6ca2690388f067175d773871f5640de57bf11aec0be258d6c7'), kind: NativeScriptKind.RequireSignature } ] @@ -270,7 +267,10 @@ describe('txInspector', () => { }, id: TransactionId('e3a443363eb6ee3d67c5e75ec10b931603787581a948d68fa3b2cd3ff2e0d2ad'), index: 0, - witness: args.witness ?? { scripts: [mockScript1], signatures: new Map() } + witness: args.witness ?? { + scripts: [mockScript1], + signatures: new Map() + } } as HydratedTx); describe('transaction sent inspector', () => { @@ -565,7 +565,7 @@ describe('txInspector', () => { 'a transaction with some certificates signed with any of the provided reward accounts' + ' and some signed with other produces an inspection containing only the former', () => { - const otherCert = { ...delegationCert, stakeKeyHash: '' as unknown as Ed25519KeyHash }; + const otherCert = { ...delegationCert, stakeKeyHash: '' as unknown as Ed25519KeyHashHex }; const tx = buildMockTx({ certificates: [delegationCert, otherCert] }); const inspectTx = createTxInspector({ signedCertificates: signedCertificatesInspector([rewardAccount]) }); const txProperties = inspectTx(tx); diff --git a/packages/dapp-connector/package.json b/packages/dapp-connector/package.json index 2fbcef6772f..c525c208ab0 100644 --- a/packages/dapp-connector/package.json +++ b/packages/dapp-connector/package.json @@ -68,6 +68,7 @@ }, "dependencies": { "@cardano-sdk/core": "^0.7.0", + "@cardano-sdk/util": "^0.7.0", "ts-custom-error": "^3.2.0", "ts-log": "^2.2.4", "webextension-polyfill": "^0.8.0" diff --git a/packages/e2e/.env.example b/packages/e2e/.env.example index aa362a57091..e8f29c40819 100644 --- a/packages/e2e/.env.example +++ b/packages/e2e/.env.example @@ -7,11 +7,11 @@ FAUCET_PROVIDER_PARAMS='{"baseUrl":"http://localhost:8090/v2","mnemonic":"fire m # Key management setup - required by getWallet KEY_MANAGEMENT_PROVIDER=inMemory -KEY_MANAGEMENT_PARAMS='{"accountIndex": 0, "chainId":{"networkId": 0, "networkMagic": 888}, "password":"some_password","mnemonic":"vacant violin soft weird deliver render brief always monitor general maid smart jelly core drastic erode echo there clump dizzy card filter option defense"}' -#KEY_MANAGEMENT_PARAMS='{"accountIndex": 0, "chainId":{"networkId": 0, "networkMagic": 888}, "password":"some_password","mnemonic":"slab gorilla reflect display cage aim silver add own arrange crew start female bitter menu inner combine exit swallow bamboo midnight wealth culture picnic"}' -#KEY_MANAGEMENT_PARAMS='{"accountIndex": 0, "chainId":{"networkId": 0, "networkMagic": 888}, "password":"some_password","mnemonic":"decorate survey empower stairs pledge humble social leisure baby wrap grief exact monster rug dash kiss perfect select science light frame play swallow day"}' -#KEY_MANAGEMENT_PARAMS='{"accountIndex": 0, "chainId":{"networkId": 0, "networkMagic": 888}, "password":"some_password","mnemonic":"phrase raw learn suspect inmate powder combine apology regular hero gain chronic fruit ritual short screen goddess odor keen creek brand today kit machine"}' -#KEY_MANAGEMENT_PARAMS='{"accountIndex": 0, "chainId":{"networkId": 0, "networkMagic": 888}, "password":"some_password","mnemonic":"salon zoo engage submit smile frost later decide wing sight chaos renew lizard rely canal coral scene hobby scare step bus leaf tobacco slice"}' +KEY_MANAGEMENT_PARAMS='{"bip32Ed25519": "CML", "accountIndex": 0, "chainId":{"networkId": 0, "networkMagic": 888}, "password":"some_password","mnemonic":"vacant violin soft weird deliver render brief always monitor general maid smart jelly core drastic erode echo there clump dizzy card filter option defense"}' +#KEY_MANAGEMENT_PARAMS='{"bip32Ed25519": "CML", "accountIndex": 0, "chainId":{"networkId": 0, "networkMagic": 888}, "password":"some_password","mnemonic":"slab gorilla reflect display cage aim silver add own arrange crew start female bitter menu inner combine exit swallow bamboo midnight wealth culture picnic"}' +#KEY_MANAGEMENT_PARAMS='{"bip32Ed25519": "CML", "accountIndex": 0, "chainId":{"networkId": 0, "networkMagic": 888}, "password":"some_password","mnemonic":"decorate survey empower stairs pledge humble social leisure baby wrap grief exact monster rug dash kiss perfect select science light frame play swallow day"}' +#KEY_MANAGEMENT_PARAMS='{"bip32Ed25519": "CML", "accountIndex": 0, "chainId":{"networkId": 0, "networkMagic": 888}, "password":"some_password","mnemonic":"phrase raw learn suspect inmate powder combine apology regular hero gain chronic fruit ritual short screen goddess odor keen creek brand today kit machine"}' +#KEY_MANAGEMENT_PARAMS='{"bip32Ed25519": "CML", "accountIndex": 0, "chainId":{"networkId": 0, "networkMagic": 888}, "password":"some_password","mnemonic":"salon zoo engage submit smile frost later decide wing sight chaos renew lizard rely canal coral scene hobby scare step bus leaf tobacco slice"}' # Providers setup - required by getWallet ASSET_PROVIDER=http diff --git a/packages/e2e/package.json b/packages/e2e/package.json index 08a9e85ea75..27bb379f54e 100644 --- a/packages/e2e/package.json +++ b/packages/e2e/package.json @@ -87,6 +87,7 @@ "@cardano-sdk/cardano-services": "^0.7.0", "@cardano-sdk/cardano-services-client": "^0.7.0", "@cardano-sdk/core": "^0.7.0", + "@cardano-sdk/crypto": "^0.1.0", "@cardano-sdk/key-management": "^0.3.0", "@cardano-sdk/ogmios": "^0.7.0", "@cardano-sdk/util": "^0.7.0", diff --git a/packages/e2e/src/environment.ts b/packages/e2e/src/environment.ts index a0c68044ae1..861987784dd 100644 --- a/packages/e2e/src/environment.ts +++ b/packages/e2e/src/environment.ts @@ -7,6 +7,7 @@ export interface KeyManagementParams { mnemonic: string; chainId: Cardano.ChainId; password: string; + bip32Ed25519: string; } export interface ProviderParams { @@ -32,11 +33,12 @@ const keyManagementParams = makeValidator((value) => { properties: { accountIndex: { minimum: 0, type: 'integer' }, + bip32Ed25519: { type: 'string' }, chainId: { $ref: '/ChainId' }, mnemonic: { type: 'string' }, password: { type: 'string' } }, - required: ['accountIndex', 'mnemonic', 'chainId', 'password'], + required: ['accountIndex', 'mnemonic', 'chainId', 'password', 'bip32Ed25519'], type: 'object' }, { diff --git a/packages/e2e/src/factories.ts b/packages/e2e/src/factories.ts index b793a33ca14..8326f906907 100644 --- a/packages/e2e/src/factories.ts +++ b/packages/e2e/src/factories.ts @@ -1,6 +1,8 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ +import * as Crypto from '@cardano-sdk/crypto'; import { AssetProvider, + CML, Cardano, ChainHistoryProvider, NetworkInfoProvider, @@ -66,8 +68,14 @@ export const rewardsProviderFactory = new ProviderFactory(); export const txSubmitProviderFactory = new ProviderFactory(); export const utxoProviderFactory = new ProviderFactory(); export const stakePoolProviderFactory = new ProviderFactory(); +export const bip32Ed25519Factory = new ProviderFactory(); + +// bip32Ed25519 + +bip32Ed25519Factory.register('CML', async () => new Crypto.CmlBip32Ed25519(CML)); // Faucet providers + faucetProviderFactory.register('cardano-wallet', CardanoWalletFaucetProvider.create); // Asset providers @@ -305,7 +313,9 @@ export const getWallet = async (props: GetWalletProps) => { const envKeyParams = customKeyParams ? customKeyParams : env.KEY_MANAGEMENT_PARAMS; const keyManagementParams = { ...envKeyParams, ...(idx === undefined ? {} : { accountIndex: idx }) }; + const bip32Ed25519 = await bip32Ed25519Factory.create(env.KEY_MANAGEMENT_PARAMS.bip32Ed25519, null, logger); const { wallet } = await setupWallet({ + bip32Ed25519, createKeyAgent: keyAgent ? () => Promise.resolve(keyAgent) : await keyManagementFactory.create(env.KEY_MANAGEMENT_PROVIDER, keyManagementParams, logger), diff --git a/packages/e2e/src/scripts/mnemonic.ts b/packages/e2e/src/scripts/mnemonic.ts index 7de07830b02..9294267aefa 100644 --- a/packages/e2e/src/scripts/mnemonic.ts +++ b/packages/e2e/src/scripts/mnemonic.ts @@ -1,6 +1,8 @@ /* eslint-disable no-console */ /* eslint-disable @typescript-eslint/no-floating-promises */ +import * as Crypto from '@cardano-sdk/crypto'; import { AddressType, InMemoryKeyAgent, util } from '@cardano-sdk/key-management'; +import { CML } from '@cardano-sdk/core'; import { localNetworkChainId } from '../util'; /** @@ -17,7 +19,11 @@ import { localNetworkChainId } from '../util'; getPassword: async () => Buffer.from(''), mnemonicWords: mnemonicArray }, - { inputResolver: { resolveInputAddress: async () => null }, logger: console } + { + bip32Ed25519: new Crypto.CmlBip32Ed25519(CML), + inputResolver: { resolveInputAddress: async () => null }, + logger: console + } ); const derivedAddress = await keyAgentFromMnemonic.deriveAddress({ diff --git a/packages/e2e/src/util/StubKeyAgent.ts b/packages/e2e/src/util/StubKeyAgent.ts index d50d0d9f81e..59638da3383 100644 --- a/packages/e2e/src/util/StubKeyAgent.ts +++ b/packages/e2e/src/util/StubKeyAgent.ts @@ -1,3 +1,4 @@ +import * as Crypto from '@cardano-sdk/crypto'; import { AccountAddressDerivationPath, AccountKeyDerivationPath, @@ -21,6 +22,10 @@ export class StubKeyAgent implements KeyAgent { return this.#knownAddresses; } + get bip32Ed25519(): Crypto.Bip32Ed25519 { + throw new NotImplementedError('bip32Ed25519'); + } + get chainId(): Cardano.ChainId { throw new NotImplementedError('chainId'); } @@ -33,7 +38,7 @@ export class StubKeyAgent implements KeyAgent { throw new NotImplementedError('serializableData'); } - get extendedAccountPublicKey(): Cardano.Bip32PublicKey { + get extendedAccountPublicKey(): Crypto.Bip32PublicKeyHex { throw new NotImplementedError('extendedAccountPublicKey'); } @@ -41,7 +46,7 @@ export class StubKeyAgent implements KeyAgent { throw new NotImplementedError('deriveAddress'); } - derivePublicKey(_derivationPath: AccountKeyDerivationPath): Promise { + derivePublicKey(_derivationPath: AccountKeyDerivationPath): Promise { throw new NotImplementedError('derivePublicKey'); } @@ -56,7 +61,7 @@ export class StubKeyAgent implements KeyAgent { throw new NotImplementedError('signTransaction'); } - exportRootPrivateKey(): Promise { + exportRootPrivateKey(): Promise { throw new NotImplementedError('exportRootPrivateKey'); } } diff --git a/packages/e2e/test/load-test-custom/wallet-init/wallet-init.test.ts b/packages/e2e/test/load-test-custom/wallet-init/wallet-init.test.ts index f73c599a2d9..94520c4c0db 100644 --- a/packages/e2e/test/load-test-custom/wallet-init/wallet-init.test.ts +++ b/packages/e2e/test/load-test-custom/wallet-init/wallet-init.test.ts @@ -13,6 +13,7 @@ import { logger } from '@cardano-sdk/util-dev'; import { MeasurementUtil, assetProviderFactory, + bip32Ed25519Factory, chainHistoryProviderFactory, getEnv, getLoadTestScheduler, @@ -70,8 +71,9 @@ const getKeyAgent = async (accountIndex: number) => { { ...env.KEY_MANAGEMENT_PARAMS, accountIndex }, logger ); + const bip32Ed25519 = await bip32Ed25519Factory.create(env.KEY_MANAGEMENT_PARAMS.bip32Ed25519, null, logger); const walletUtil = createLazyWalletUtil(); - const keyAgent = await createKeyAgent({ inputResolver: walletUtil, logger }); + const keyAgent = await createKeyAgent({ bip32Ed25519, inputResolver: walletUtil, logger }); return { keyAgent, walletUtil }; }; diff --git a/packages/e2e/test/local-network/register-pool.test.ts b/packages/e2e/test/local-network/register-pool.test.ts index 6286eb00b73..1d2d0e15d1e 100644 --- a/packages/e2e/test/local-network/register-pool.test.ts +++ b/packages/e2e/test/local-network/register-pool.test.ts @@ -74,7 +74,8 @@ describe('local-network/register-pool', () => { role: KeyRole.External }); - const poolKeyHash = Cardano.Ed25519KeyHash.fromKey(poolPubKey); + const bip32Ed25519 = await poolKeyAgent.getBip32Ed25519(); + const poolKeyHash = await bip32Ed25519.getPubKeyHash(poolPubKey); const poolId = Cardano.PoolId.fromKeyHash(poolKeyHash); const poolRewardAccount = ( await poolKeyAgent.deriveAddress({ @@ -104,7 +105,7 @@ describe('local-network/register-pool', () => { }; const rewardAccounts = await firstValueFrom(wallet.delegation.rewardAccounts$); - const stakeKeyHash = Cardano.Ed25519KeyHash.fromRewardAccount(rewardAccounts[0].address); + const stakeKeyHash = Cardano.RewardAccount.toHash(rewardAccounts[0].address); await submitCertificate(registrationCert, wallet1); @@ -155,7 +156,8 @@ describe('local-network/register-pool', () => { role: KeyRole.External }); - const poolKeyHash = Cardano.Ed25519KeyHash.fromKey(poolPubKey); + const bip32Ed25519 = await poolKeyAgent.getBip32Ed25519(); + const poolKeyHash = await bip32Ed25519.getPubKeyHash(poolPubKey); const poolId = Cardano.PoolId.fromKeyHash(poolKeyHash); const poolRewardAccount = ( await poolKeyAgent.deriveAddress({ @@ -185,7 +187,7 @@ describe('local-network/register-pool', () => { }; const rewardAccounts = await firstValueFrom(wallet.delegation.rewardAccounts$); - const stakeKeyHash = Cardano.Ed25519KeyHash.fromRewardAccount(rewardAccounts[0].address); + const stakeKeyHash = Cardano.RewardAccount.toHash(rewardAccounts[0].address); await submitCertificate(registrationCert, wallet2); diff --git a/packages/e2e/test/long-running/cache-invalidation.test.ts b/packages/e2e/test/long-running/cache-invalidation.test.ts index 0edbed1b358..77ba50aec13 100644 --- a/packages/e2e/test/long-running/cache-invalidation.test.ts +++ b/packages/e2e/test/long-running/cache-invalidation.test.ts @@ -55,7 +55,8 @@ describe('cache invalidation', () => { role: KeyRole.External }); - const poolKeyHash = Cardano.Ed25519KeyHash.fromKey(poolPubKey); + const bip32Ed25519 = await poolKeyAgent.getBip32Ed25519(); + const poolKeyHash = await bip32Ed25519.getPubKeyHash(poolPubKey); const poolId = Cardano.PoolId.fromKeyHash(poolKeyHash); const poolRewardAccount = ( await poolKeyAgent.deriveAddress({ diff --git a/packages/e2e/test/util.ts b/packages/e2e/test/util.ts index 96e7ccb03bf..e46f362560e 100644 --- a/packages/e2e/test/util.ts +++ b/packages/e2e/test/util.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ +import * as Crypto from '@cardano-sdk/crypto'; import * as envalid from 'envalid'; import { Cardano, createSlotEpochCalc } from '@cardano-sdk/core'; import { @@ -239,13 +240,18 @@ export const submitCertificate = async (certificate: Cardano.Certificate, wallet * * @param mnemonics The random set of mnemonics. * @param genesis Network genesis parameters + * @param bip32Ed25519 The Ed25519 cryptography implementation. */ -export const createStandaloneKeyAgent = async (mnemonics: string[], genesis: Cardano.CompactGenesis) => +export const createStandaloneKeyAgent = async ( + mnemonics: string[], + genesis: Cardano.CompactGenesis, + bip32Ed25519: Crypto.Bip32Ed25519 +) => await InMemoryKeyAgent.fromBip39MnemonicWords( { chainId: genesis, getPassword: async () => Buffer.from(''), mnemonicWords: mnemonics }, - { inputResolver: { resolveInputAddress: async () => null }, logger } + { bip32Ed25519, inputResolver: { resolveInputAddress: async () => null }, logger } ); diff --git a/packages/e2e/test/wallet/SingleAddressWallet/mint.test.ts b/packages/e2e/test/wallet/SingleAddressWallet/mint.test.ts index 47a42de31e0..bde2bb87684 100644 --- a/packages/e2e/test/wallet/SingleAddressWallet/mint.test.ts +++ b/packages/e2e/test/wallet/SingleAddressWallet/mint.test.ts @@ -24,7 +24,11 @@ describe('SingleAddressWallet/mint', () => { const genesis = await firstValueFrom(wallet.genesisParameters$); - const aliceKeyAgent = await createStandaloneKeyAgent(util.generateMnemonicWords(), genesis); + const aliceKeyAgent = await createStandaloneKeyAgent( + util.generateMnemonicWords(), + genesis, + await wallet.keyAgent.getBip32Ed25519() + ); const derivationPath = { index: 0, @@ -32,7 +36,7 @@ describe('SingleAddressWallet/mint', () => { }; const alicePubKey = await aliceKeyAgent.derivePublicKey(derivationPath); - const aliceKeyHash = Cardano.Ed25519KeyHash.fromKey(alicePubKey); + const aliceKeyHash = await aliceKeyAgent.bip32Ed25519.getPubKeyHash(alicePubKey); const alicePolicySigner = new util.KeyAgentTransactionSigner(aliceKeyAgent, derivationPath); diff --git a/packages/e2e/test/wallet/SingleAddressWallet/multisignature.test.ts b/packages/e2e/test/wallet/SingleAddressWallet/multisignature.test.ts index 2ed36230722..216c428b1e9 100644 --- a/packages/e2e/test/wallet/SingleAddressWallet/multisignature.test.ts +++ b/packages/e2e/test/wallet/SingleAddressWallet/multisignature.test.ts @@ -25,8 +25,16 @@ describe('SingleAddressWallet/multisignature', () => { const genesis = await firstValueFrom(wallet.genesisParameters$); - const aliceKeyAgent = await createStandaloneKeyAgent(util.generateMnemonicWords(), genesis); - const bobKeyAgent = await createStandaloneKeyAgent(util.generateMnemonicWords(), genesis); + const aliceKeyAgent = await createStandaloneKeyAgent( + util.generateMnemonicWords(), + genesis, + await wallet.keyAgent.getBip32Ed25519() + ); + const bobKeyAgent = await createStandaloneKeyAgent( + util.generateMnemonicWords(), + genesis, + await wallet.keyAgent.getBip32Ed25519() + ); const derivationPath = { index: 0, @@ -34,10 +42,10 @@ describe('SingleAddressWallet/multisignature', () => { }; const alicePubKey = await aliceKeyAgent.derivePublicKey(derivationPath); - const aliceKeyHash = Cardano.Ed25519KeyHash.fromKey(alicePubKey); + const aliceKeyHash = await aliceKeyAgent.bip32Ed25519.getPubKeyHash(alicePubKey); const bobPubKey = await bobKeyAgent.derivePublicKey(derivationPath); - const bobKeyHash = Cardano.Ed25519KeyHash.fromKey(bobPubKey); + const bobKeyHash = await bobKeyAgent.bip32Ed25519.getPubKeyHash(bobPubKey); const alicePolicySigner = new util.KeyAgentTransactionSigner(aliceKeyAgent, derivationPath); const bobPolicySigner = new util.KeyAgentTransactionSigner(bobKeyAgent, derivationPath); diff --git a/packages/e2e/test/wallet/SingleAddressWallet/nft.test.ts b/packages/e2e/test/wallet/SingleAddressWallet/nft.test.ts index 77dba5b591e..2be219561e5 100644 --- a/packages/e2e/test/wallet/SingleAddressWallet/nft.test.ts +++ b/packages/e2e/test/wallet/SingleAddressWallet/nft.test.ts @@ -22,7 +22,6 @@ describe('SingleAddressWallet.assets/nft', () => { let assetIds: Cardano.AssetId[]; let fingerprints: Cardano.AssetFingerprint[]; const assetNames = ['4e46542d66696c6573', '4e46542d303031', '4e46542d303032']; - let walletAddress: Cardano.Address; beforeAll(async () => { @@ -32,14 +31,18 @@ describe('SingleAddressWallet.assets/nft', () => { const genesis = await firstValueFrom(wallet.genesisParameters$); - const keyAgent = await createStandaloneKeyAgent(util.generateMnemonicWords(), genesis); + const keyAgent = await createStandaloneKeyAgent( + util.generateMnemonicWords(), + genesis, + await wallet.keyAgent.getBip32Ed25519() + ); const pubKey = await keyAgent.derivePublicKey({ index: 0, role: KeyRole.External }); - const keyHash = Cardano.Ed25519KeyHash.fromKey(pubKey); + const keyHash = await keyAgent.bip32Ed25519.getPubKeyHash(pubKey); policySigner = new util.KeyAgentTransactionSigner(keyAgent, { index: 0, diff --git a/packages/e2e/test/web-extension/extension/ui.ts b/packages/e2e/test/web-extension/extension/ui.ts index 7ba1a4309c7..6cc688c2481 100644 --- a/packages/e2e/test/web-extension/extension/ui.ts +++ b/packages/e2e/test/web-extension/extension/ui.ts @@ -9,7 +9,7 @@ import { exposeApi } from '@cardano-sdk/web-extension'; import { adaPriceServiceChannel, getObservableWalletName, userPromptServiceChannel, walletName } from './const'; -import { keyManagementFactory } from '../../../src'; +import { bip32Ed25519Factory, keyManagementFactory } from '../../../src'; import { combineLatest, firstValueFrom, of } from 'rxjs'; import { runtime } from 'webextension-polyfill'; @@ -114,6 +114,7 @@ const createWallet = async (accountIndex: number) => { // setupWallet call is required to provide context (InputResolver) to the key agent const { keyAgent } = await setupWallet({ + bip32Ed25519: await bip32Ed25519Factory.create(env.KEY_MANAGEMENT_PARAMS.bip32Ed25519, null, logger), createKeyAgent: async (dependencies) => ( await keyManagementFactory.create( diff --git a/packages/governance/package.json b/packages/governance/package.json index 534f375106c..dda70a16244 100644 --- a/packages/governance/package.json +++ b/packages/governance/package.json @@ -60,6 +60,7 @@ }, "dependencies": { "@cardano-sdk/core": "^0.7.0", + "@cardano-sdk/crypto": "^0.1.0", "@cardano-sdk/key-management": "^0.3.0", "@cardano-sdk/util": "^0.7.0", "blake2b": "^2.1.4" diff --git a/packages/governance/src/cip36.ts b/packages/governance/src/cip36.ts index 4a8777dfde7..bfc4f29b00d 100644 --- a/packages/governance/src/cip36.ts +++ b/packages/governance/src/cip36.ts @@ -1,3 +1,4 @@ +import * as Crypto from '@cardano-sdk/crypto'; import { CML, Cardano, coreToCml, util } from '@cardano-sdk/core'; import { HexBlob, usingAutoFree } from '@cardano-sdk/util'; import { util as keyManagementUtil } from '@cardano-sdk/key-management'; @@ -28,7 +29,7 @@ export enum VotingKeyDerivationPath { * Voting power delegation to a specified voting key */ export interface GovernanceKeyDelegation { - votingKey: Cardano.Ed25519PublicKey; + votingKey: Crypto.Ed25519PublicKeyHex; /** * Integer >0 */ @@ -44,7 +45,7 @@ export enum VotingPurpose { export interface BuildVotingRegistrationProps { delegations: GovernanceKeyDelegation[]; - stakeKey: Cardano.Ed25519PublicKey; + stakeKey: Crypto.Ed25519PublicKeyHex; rewardAccount: Cardano.RewardAccount; purpose: VotingPurpose; nonce?: number; @@ -57,7 +58,7 @@ export interface BlobSigner { /** * Sign blob with some key */ - signBlob(blob: HexBlob): Promise; + signBlob(blob: HexBlob): Promise; } export const metadataBuilder = { diff --git a/packages/governance/test/cip36.test.ts b/packages/governance/test/cip36.test.ts index ef316fdbe53..c5c27797a26 100644 --- a/packages/governance/test/cip36.test.ts +++ b/packages/governance/test/cip36.test.ts @@ -1,7 +1,9 @@ /* eslint-disable max-len */ +import * as Crypto from '@cardano-sdk/crypto'; import { CML, Cardano, coreToCml } from '@cardano-sdk/core'; import { cip36 } from '../src'; import { usingAutoFree } from '@cardano-sdk/util'; + import delay from 'delay'; describe('cip36', () => { @@ -10,13 +12,13 @@ describe('cip36', () => { const props: cip36.BuildVotingRegistrationProps = { delegations: [ { - votingKey: Cardano.Ed25519PublicKey('a6a3c0447aeb9cc54cf6422ba32b294e5e1c3ef6d782f2acff4a70694c4d1663'), + votingKey: Crypto.Ed25519PublicKeyHex('a6a3c0447aeb9cc54cf6422ba32b294e5e1c3ef6d782f2acff4a70694c4d1663'), weight: 1 } ], purpose: cip36.VotingPurpose.CATALYST, rewardAccount: Cardano.RewardAccount('stake_test1uzhr5zn6akj2affzua8ylcm8t872spuf5cf6tzjrvnmwemcehgcjm'), - stakeKey: Cardano.Ed25519PublicKey('86870efc99c453a873a16492ce87738ec79a0ebd064379a62e2c9cf4e119219e') + stakeKey: Crypto.Ed25519PublicKeyHex('86870efc99c453a873a16492ce87738ec79a0ebd064379a62e2c9cf4e119219e') }; const getNonce = (metadata: Cardano.TxMetadata) => (metadata.get(61_284n) as Cardano.MetadatumMap).get(4n) as bigint; @@ -30,18 +32,18 @@ describe('cip36', () => { const votingRegistrationMetadata = cip36.metadataBuilder.buildVotingRegistration({ delegations: [ { - votingKey: Cardano.Ed25519PublicKey('a6a3c0447aeb9cc54cf6422ba32b294e5e1c3ef6d782f2acff4a70694c4d1663'), + votingKey: Crypto.Ed25519PublicKeyHex('a6a3c0447aeb9cc54cf6422ba32b294e5e1c3ef6d782f2acff4a70694c4d1663'), weight: 1 }, { - votingKey: Cardano.Ed25519PublicKey('00588e8e1d18cba576a4d35758069fe94e53f638b6faf7c07b8abd2bc5c5cdee'), + votingKey: Crypto.Ed25519PublicKeyHex('00588e8e1d18cba576a4d35758069fe94e53f638b6faf7c07b8abd2bc5c5cdee'), weight: 3 } ], nonce: 1234, purpose: cip36.VotingPurpose.CATALYST, rewardAccount: Cardano.RewardAccount('stake_test1uzhr5zn6akj2affzua8ylcm8t872spuf5cf6tzjrvnmwemcehgcjm'), - stakeKey: Cardano.Ed25519PublicKey('86870efc99c453a873a16492ce87738ec79a0ebd064379a62e2c9cf4e119219e') + stakeKey: Crypto.Ed25519PublicKeyHex('86870efc99c453a873a16492ce87738ec79a0ebd064379a62e2c9cf4e119219e') }); expect( Buffer.from( @@ -55,7 +57,7 @@ describe('cip36', () => { const privateStakeKey = CML.PrivateKey.from_normal_bytes( Buffer.from('f5beaeff7932a4164d270afde7716067582412e8977e67986cd9b456fc082e3a', 'hex') ); - return Cardano.Ed25519Signature(privateStakeKey.sign(Buffer.from(blob, 'hex')).to_hex()); + return Crypto.Ed25519SignatureHex(privateStakeKey.sign(Buffer.from(blob, 'hex')).to_hex()); } }); expect((signedCip36Metadata.get(61_285n) as Cardano.MetadatumMap).get(1n)).toEqual( diff --git a/packages/governance/test/integration/cip36KeyAgents.test.ts b/packages/governance/test/integration/cip36KeyAgents.test.ts index 49a66f353b2..9c769b41b78 100644 --- a/packages/governance/test/integration/cip36KeyAgents.test.ts +++ b/packages/governance/test/integration/cip36KeyAgents.test.ts @@ -23,14 +23,15 @@ describe('cip36', () => { // - it can also be a separate key agent, then it would be using a different seedphrase, // but right now it's the only way to support voting when stake key is controlled by a HW device. const votingKeyAgent: InMemoryKeyAgent = (await testKeyAgent()) as unknown as InMemoryKeyAgent; - votingKeyPair = util.toEd25519KeyPair( + votingKeyPair = await util.toEd25519KeyPair( await votingKeyAgent.exportExtendedKeyPair([ cip36.VotingKeyDerivationPath.PURPOSE, cip36.VotingKeyDerivationPath.COIN_TYPE, - util.harden(walletKeyAgent.accountIndex), // using same account index as wallet's key agent here + walletKeyAgent.accountIndex, // using same account index as wallet's key agent here 0, // chain as per cip36 0 // address_index as per cip36 - ]) + ]), + votingKeyAgent.bip32Ed25519 ); }); diff --git a/packages/key-management/package.json b/packages/key-management/package.json index 919ab2b7e3a..8a4cc215687 100644 --- a/packages/key-management/package.json +++ b/packages/key-management/package.json @@ -61,8 +61,10 @@ "dependencies": { "@cardano-foundation/ledgerjs-hw-app-cardano": "^5.0.0", "@cardano-sdk/core": "^0.7.0", + "@cardano-sdk/crypto": "^0.1.0", "@cardano-sdk/dapp-connector": "^0.6.1", "@cardano-sdk/util": "^0.7.0", + "@cardano-sdk/util-dev": "^0.6.0", "@emurgo/cardano-message-signing-nodejs": "^1.0.1", "@ledgerhq/hw-transport": "^6.27.2", "@ledgerhq/hw-transport-node-hid-noevents": "^6.27.2", diff --git a/packages/key-management/src/InMemoryKeyAgent.ts b/packages/key-management/src/InMemoryKeyAgent.ts index 40a64ab206d..67d0926dca0 100644 --- a/packages/key-management/src/InMemoryKeyAgent.ts +++ b/packages/key-management/src/InMemoryKeyAgent.ts @@ -1,3 +1,4 @@ +import * as Crypto from '@cardano-sdk/crypto'; import * as errors from './errors'; import { AccountKeyDerivationPath, @@ -10,7 +11,7 @@ import { SignBlobResult, SignTransactionOptions } from './types'; -import { CML, Cardano, util } from '@cardano-sdk/core'; +import { Cardano } from '@cardano-sdk/core'; import { HexBlob } from '@cardano-sdk/util'; import { KeyAgentBase } from './KeyAgentBase'; import { @@ -31,7 +32,7 @@ export interface InMemoryKeyAgentProps extends Omit { const rootPrivateKey = await this.#decryptRootPrivateKey(); - const accountKey = deriveAccountPrivateKey({ + const accountKey = await deriveAccountPrivateKey({ accountIndex: this.accountIndex, + bip32Ed25519: this.bip32Ed25519, rootPrivateKey }); - const signingKey = accountKey.derive(type).derive(index).to_raw_key(); - const signature = Cardano.Ed25519Signature(signingKey.sign(Buffer.from(blob, 'hex')).to_hex()); - const publicKey = Cardano.Ed25519PublicKey.fromHexBlob(util.bytesToHex(signingKey.to_public().as_bytes())); + + const bip32SigningKey = await this.bip32Ed25519.derivePrivateKey(accountKey, [type, index]); + const signingKey = await this.bip32Ed25519.getRawPrivateKey(bip32SigningKey); + const signature = await this.bip32Ed25519.sign(signingKey, blob); + const publicKey = await this.bip32Ed25519.getPublicKey(signingKey); + return { publicKey, signature }; } // To export mnemonic, get entropy by reversing this: + // rootPrivateKey = CML.Bip32PrivateKey.from_bip39_entropy(entropy, EMPTY_PASSWORD); // eslint-disable-next-line max-len // https://github.com/Emurgo/cardano-serialization-lib/blob/f817a033ade7a2255591d7c6444fa4f9ffbcf061/rust/src/chain_crypto/derive.rs#L30-L38 - async exportRootPrivateKey(): Promise { - const rootPrivateKey = await this.#decryptRootPrivateKey(true); - return Cardano.Bip32PrivateKey.fromHexBlob(util.bytesToHex(rootPrivateKey.as_bytes())); + async exportRootPrivateKey(): Promise { + return await this.#decryptRootPrivateKey(true); } /** @@ -81,7 +86,7 @@ export class InMemoryKeyAgent extends KeyAgentBase implements KeyAgent { chainId, getPassword, mnemonicWords, - mnemonic2ndFactorPassphrase = Buffer.from(''), + mnemonic2ndFactorPassphrase = '', accountIndex = 0 }: FromBip39MnemonicWordsProps, dependencies: KeyAgentDependencies @@ -90,16 +95,17 @@ export class InMemoryKeyAgent extends KeyAgentBase implements KeyAgent { const validMnemonic = validateMnemonic(mnemonic); if (!validMnemonic) throw new errors.InvalidMnemonicError(); const entropy = Buffer.from(mnemonicWordsToEntropy(mnemonicWords), 'hex'); - const rootPrivateKey = CML.Bip32PrivateKey.from_bip39_entropy(entropy, mnemonic2ndFactorPassphrase); + const rootPrivateKey = await dependencies.bip32Ed25519.fromBip39Entropy(entropy, mnemonic2ndFactorPassphrase); const password = await getPasswordRethrowTypedError(getPassword); - const encryptedRootPrivateKey = await emip3encrypt(rootPrivateKey.as_bytes(), password); - const accountPrivateKey = deriveAccountPrivateKey({ + const encryptedRootPrivateKey = await emip3encrypt(Buffer.from(rootPrivateKey, 'hex'), password); + const accountPrivateKey = await deriveAccountPrivateKey({ accountIndex, + bip32Ed25519: dependencies.bip32Ed25519, rootPrivateKey }); - const extendedAccountPublicKey = Cardano.Bip32PublicKey( - Buffer.from(accountPrivateKey.to_public().as_bytes()).toString('hex') - ); + + const extendedAccountPublicKey = await dependencies.bip32Ed25519.getBip32PublicKey(accountPrivateKey); + return new InMemoryKeyAgent( { accountIndex, @@ -125,7 +131,7 @@ export class InMemoryKeyAgent extends KeyAgentBase implements KeyAgent { // if (keyPaths.length === 0) { // throw new ProofGenerationError(); // } - return new Map( + return new Map( await Promise.all( keyPaths.map(async ({ role, index }) => { const { publicKey, signature } = await this.signBlob({ index, role }, blob); @@ -140,14 +146,12 @@ export class InMemoryKeyAgent extends KeyAgentBase implements KeyAgent { */ async exportExtendedKeyPair(derivationPath: number[]): Promise { const rootPrivateKey = await this.exportRootPrivateKey(); - const cslRootPrivateKey = CML.Bip32PrivateKey.from_bytes(Buffer.from(rootPrivateKey, 'hex')); - let cslPrivateKey = cslRootPrivateKey; - for (const val of derivationPath) { - cslPrivateKey = cslPrivateKey.derive(harden(val)); - } + const hardenedIndices = derivationPath.map((index: number) => harden(index)); + const childKey = await this.bip32Ed25519.derivePrivateKey(rootPrivateKey, hardenedIndices); + return { - skey: Cardano.Bip32PrivateKey(Buffer.from(cslPrivateKey.as_bytes()).toString('hex')), - vkey: Cardano.Bip32PublicKey(Buffer.from(cslPrivateKey.to_public().as_bytes()).toString('hex')) + skey: childKey, + vkey: await this.bip32Ed25519.getBip32PublicKey(childKey) }; } @@ -162,6 +166,6 @@ export class InMemoryKeyAgent extends KeyAgentBase implements KeyAgent { } catch (error) { throw new errors.AuthenticationError('Failed to decrypt root private key', error); } - return CML.Bip32PrivateKey.from_bytes(decryptedRootKeyBytes); + return Crypto.Bip32PrivateKeyHex(Buffer.from(decryptedRootKeyBytes).toString('hex')); } } diff --git a/packages/key-management/src/KeyAgentBase.ts b/packages/key-management/src/KeyAgentBase.ts index 111fef93e17..7cf4d37e0aa 100644 --- a/packages/key-management/src/KeyAgentBase.ts +++ b/packages/key-management/src/KeyAgentBase.ts @@ -1,3 +1,4 @@ +import * as Crypto from '@cardano-sdk/crypto'; import { AccountAddressDerivationPath, AccountKeyDerivationPath, @@ -9,12 +10,13 @@ import { SignBlobResult, SignTransactionOptions } from './types'; -import { CML, Cardano, util } from '@cardano-sdk/core'; -import { HexBlob } from '@cardano-sdk/util'; +import { CML, Cardano } from '@cardano-sdk/core'; +import { HexBlob, usingAutoFree } from '@cardano-sdk/util'; import { STAKE_KEY_DERIVATION_PATH } from './util'; export abstract class KeyAgentBase implements KeyAgent { readonly #serializableData: SerializableKeyAgentData; + readonly #bip32Ed25519: Crypto.Bip32Ed25519; protected readonly inputResolver: Cardano.util.InputResolver; get knownAddresses(): GroupedAddress[] { @@ -26,7 +28,7 @@ export abstract class KeyAgentBase implements KeyAgent { get serializableData(): SerializableKeyAgentData { return this.#serializableData; } - get extendedAccountPublicKey(): Cardano.Bip32PublicKey { + get extendedAccountPublicKey(): Crypto.Bip32PublicKeyHex { return this.serializableData.extendedAccountPublicKey; } get chainId(): Cardano.ChainId { @@ -35,16 +37,21 @@ export abstract class KeyAgentBase implements KeyAgent { get accountIndex(): number { return this.serializableData.accountIndex; } + get bip32Ed25519(): Crypto.Bip32Ed25519 { + return this.#bip32Ed25519; + } + abstract signBlob(derivationPath: AccountKeyDerivationPath, blob: HexBlob): Promise; - abstract exportRootPrivateKey(): Promise; + abstract exportRootPrivateKey(): Promise; abstract signTransaction( txInternals: Cardano.TxBodyWithHash, signTransactionOptions?: SignTransactionOptions ): Promise; - constructor(serializableData: SerializableKeyAgentData, { inputResolver }: KeyAgentDependencies) { + constructor(serializableData: SerializableKeyAgentData, { inputResolver, bip32Ed25519 }: KeyAgentDependencies) { this.#serializableData = serializableData; this.inputResolver = inputResolver; + this.#bip32Ed25519 = bip32Ed25519; } /** @@ -53,44 +60,64 @@ export abstract class KeyAgentBase implements KeyAgent { async deriveAddress({ index, type }: AccountAddressDerivationPath): Promise { const knownAddress = this.knownAddresses.find((addr) => addr.type === type && addr.index === index); if (knownAddress) return knownAddress; - const derivedPublicPaymentKey = await this.deriveCmlPublicKey({ + const derivedPublicPaymentKey = await this.derivePublicKey({ index, role: type as unknown as KeyRole }); + const derivedPublicPaymentKeyHash = await this.#bip32Ed25519.getPubKeyHash(derivedPublicPaymentKey); + // Possible optimization: memoize/cache stakeKeyCredential, because it's always the same - const publicStakeKey = await this.deriveCmlPublicKey(STAKE_KEY_DERIVATION_PATH); - const stakeKeyCredential = CML.StakeCredential.from_keyhash(publicStakeKey.hash()); + const publicStakeKey = await this.derivePublicKey(STAKE_KEY_DERIVATION_PATH); + const publicStakeKeyHash = await this.#bip32Ed25519.getPubKeyHash(publicStakeKey); - const address = CML.BaseAddress.new( - this.chainId.networkId, - CML.StakeCredential.from_keyhash(derivedPublicPaymentKey.hash()), - stakeKeyCredential - ).to_address(); + const groupedAddress = usingAutoFree((scope) => { + const stakeKeyCredential = scope.manage( + CML.StakeCredential.from_keyhash( + scope.manage(CML.Ed25519KeyHash.from_bytes(Buffer.from(publicStakeKeyHash, 'hex'))) + ) + ); - const rewardAccount = CML.RewardAddress.new(this.chainId.networkId, stakeKeyCredential).to_address(); - const groupedAddress = { - accountIndex: this.accountIndex, - address: Cardano.Address(address.to_bech32()), - index, - networkId: this.chainId.networkId, - rewardAccount: Cardano.RewardAccount(rewardAccount.to_bech32()), - stakeKeyDerivationPath: STAKE_KEY_DERIVATION_PATH, - type - }; + const address = scope.manage( + scope + .manage( + CML.BaseAddress.new( + this.chainId.networkId, + scope.manage( + CML.StakeCredential.from_keyhash( + scope.manage(CML.Ed25519KeyHash.from_bytes(Buffer.from(derivedPublicPaymentKeyHash, 'hex'))) + ) + ), + stakeKeyCredential + ) + ) + .to_address() + ); + + const rewardAccount = scope.manage( + scope.manage(CML.RewardAddress.new(this.chainId.networkId, stakeKeyCredential)).to_address() + ); + return { + accountIndex: this.accountIndex, + address: Cardano.Address(address.to_bech32()), + index, + networkId: this.chainId.networkId, + rewardAccount: Cardano.RewardAccount(rewardAccount.to_bech32()), + stakeKeyDerivationPath: STAKE_KEY_DERIVATION_PATH, + type + }; + }); this.knownAddresses = [...this.knownAddresses, groupedAddress]; return groupedAddress; } - async derivePublicKey(derivationPath: AccountKeyDerivationPath): Promise { - const cslPublicKey = await this.deriveCmlPublicKey(derivationPath); - return Cardano.Ed25519PublicKey.fromHexBlob(util.bytesToHex(cslPublicKey.as_bytes())); - } + async derivePublicKey(derivationPath: AccountKeyDerivationPath): Promise { + const childKey = await this.#bip32Ed25519.derivePublicKey(this.extendedAccountPublicKey, [ + derivationPath.role, + derivationPath.index + ]); - protected async deriveCmlPublicKey({ index, role: type }: AccountKeyDerivationPath): Promise { - const accountPublicKeyBytes = Buffer.from(this.extendedAccountPublicKey, 'hex'); - const accountPublicKey = CML.Bip32PublicKey.from_bytes(accountPublicKeyBytes); - return accountPublicKey.derive(type).derive(index).to_raw_key(); + return await this.#bip32Ed25519.getRawPublicKey(childKey); } } diff --git a/packages/key-management/src/LedgerKeyAgent.ts b/packages/key-management/src/LedgerKeyAgent.ts index 16cfbcce2dd..34563650574 100644 --- a/packages/key-management/src/LedgerKeyAgent.ts +++ b/packages/key-management/src/LedgerKeyAgent.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ +import * as Crypto from '@cardano-sdk/crypto'; import { AuthenticationError, TransportError } from './errors'; import { Cardano, NotImplementedError, coreToCml } from '@cardano-sdk/core'; import { @@ -163,7 +164,7 @@ export class LedgerKeyAgent extends KeyAgentBase { deviceConnection, communicationType, accountIndex - }: GetLedgerXpubProps): Promise { + }: GetLedgerXpubProps): Promise { try { const recoveredDeviceConnection = await LedgerKeyAgent.checkDeviceConnection(communicationType, deviceConnection); const derivationPath = `${CardanoKeyConst.PURPOSE}'/${CardanoKeyConst.COIN_TYPE}'/${accountIndex}'`; @@ -171,7 +172,7 @@ export class LedgerKeyAgent extends KeyAgentBase { path: utils.str_to_path(derivationPath) // BIP32Path }); const xPubHex = `${extendedPublicKey.publicKeyHex}${extendedPublicKey.chainCodeHex}`; - return Cardano.Bip32PublicKey(xPubHex); + return Crypto.Bip32PublicKeyHex(xPubHex); } catch (error: any) { if (error.code === 28_169) { throw new AuthenticationError('Failed to export extended account public key', error); @@ -239,14 +240,14 @@ export class LedgerKeyAgent extends KeyAgentBase { ); const result = await deviceConnection.signTransaction(ledgerTxData); - return new Map( + return new Map( await Promise.all( result.witnesses.map(async (witness) => { const publicKey = await this.derivePublicKey({ index: witness.path[Cip1852PathLevelIndexes.INDEX], role: witness.path[Cip1852PathLevelIndexes.ROLE] }); - const signature = Cardano.Ed25519Signature(witness.witnessSignatureHex); + const signature = Crypto.Ed25519SignatureHex(witness.witnessSignatureHex); return [publicKey, signature] as const; }) ) @@ -265,7 +266,7 @@ export class LedgerKeyAgent extends KeyAgentBase { throw new NotImplementedError('signBlob'); } - async exportRootPrivateKey(): Promise { + async exportRootPrivateKey(): Promise { throw new NotImplementedError('Operation not supported!'); } } diff --git a/packages/key-management/src/TrezorKeyAgent.ts b/packages/key-management/src/TrezorKeyAgent.ts index 2c0b52523d0..536a5c25ccd 100644 --- a/packages/key-management/src/TrezorKeyAgent.ts +++ b/packages/key-management/src/TrezorKeyAgent.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ +import * as Crypto from '@cardano-sdk/crypto'; import { AuthenticationError, TransportError } from './errors'; import { Cardano, NotImplementedError, coreToCml } from '@cardano-sdk/core'; import { @@ -92,7 +93,7 @@ export class TrezorKeyAgent extends KeyAgentBase { /** * @throws AuthenticationError */ - static async getXpub({ accountIndex }: GetTrezorXpubProps): Promise { + static async getXpub({ accountIndex }: GetTrezorXpubProps): Promise { try { await TrezorKeyAgent.checkDeviceConnection(); const derivationPath = `m/${CardanoKeyConst.PURPOSE}'/${CardanoKeyConst.COIN_TYPE}'/${accountIndex}'`; @@ -103,7 +104,7 @@ export class TrezorKeyAgent extends KeyAgentBase { if (!extendedPublicKey.success) { throw new TransportError('Failed to export extended account public key', extendedPublicKey.payload); } - return Cardano.Bip32PublicKey(extendedPublicKey.payload.publicKey); + return Crypto.Bip32PublicKeyHex(extendedPublicKey.payload.publicKey); } catch (error: any) { throw transportTypedError(error); } @@ -150,11 +151,11 @@ export class TrezorKeyAgent extends KeyAgentBase { } const signedData = result.payload; - return new Map( + return new Map( await Promise.all( signedData.witnesses.map(async (witness) => { - const publicKey = Cardano.Ed25519PublicKey(witness.pubKey); - const signature = Cardano.Ed25519Signature(witness.signature); + const publicKey = Crypto.Ed25519PublicKeyHex(witness.pubKey); + const signature = Crypto.Ed25519SignatureHex(witness.signature); return [publicKey, signature] as const; }) ) @@ -173,7 +174,7 @@ export class TrezorKeyAgent extends KeyAgentBase { throw new NotImplementedError('signBlob'); } - async exportRootPrivateKey(): Promise { + async exportRootPrivateKey(): Promise { throw new NotImplementedError('Operation not supported!'); } } diff --git a/packages/key-management/src/cip8/cip30signData.ts b/packages/key-management/src/cip8/cip30signData.ts index 375d4b030c6..b246ae93af4 100644 --- a/packages/key-management/src/cip8/cip30signData.ts +++ b/packages/key-management/src/cip8/cip30signData.ts @@ -1,3 +1,4 @@ +import * as Crypto from '@cardano-sdk/crypto'; import { AccountKeyDerivationPath } from '..'; import { AlgorithmId, @@ -80,7 +81,7 @@ const signSigStructure = ( } }; -const createCoseKey = (addressBytes: Uint8Array, publicKey: Cardano.Ed25519PublicKey) => { +const createCoseKey = (addressBytes: Uint8Array, publicKey: Crypto.Ed25519PublicKeyHex) => { const coseKey = COSEKey.new(Label.from_key_type(COSEKeyType.OKP)); coseKey.set_key_id(addressBytes); coseKey.set_algorithm_id(Label.from_algorithm_id(AlgorithmId.EdDSA)); diff --git a/packages/key-management/src/types.ts b/packages/key-management/src/types.ts index e0c6b8bab13..e61a0291681 100644 --- a/packages/key-management/src/types.ts +++ b/packages/key-management/src/types.ts @@ -1,3 +1,4 @@ +import * as Crypto from '@cardano-sdk/crypto'; import { Cardano } from '@cardano-sdk/core'; import { HexBlob, Shutdown } from '@cardano-sdk/util'; import { Logger } from 'ts-log'; @@ -6,8 +7,8 @@ import TransportNodeHid from '@ledgerhq/hw-transport-node-hid-noevents'; import TransportWebHID from '@ledgerhq/hw-transport-webhid'; export interface SignBlobResult { - publicKey: Cardano.Ed25519PublicKey; - signature: Cardano.Ed25519Signature; + publicKey: Crypto.Ed25519PublicKeyHex; + signature: Crypto.Ed25519SignatureHex; } export enum CardanoKeyConst { @@ -61,11 +62,10 @@ export enum CommunicationType { Node = 'node' } -export type BIP32Path = Array; - export interface KeyAgentDependencies { inputResolver: Cardano.util.InputResolver; logger: Logger; + bip32Ed25519: Crypto.Bip32Ed25519; } export interface AccountAddressDerivationPath { @@ -97,7 +97,7 @@ export interface SerializableKeyAgentDataBase { chainId: Cardano.ChainId; accountIndex: number; knownAddresses: GroupedAddress[]; - extendedAccountPublicKey: Cardano.Bip32PublicKey; + extendedAccountPublicKey: Crypto.Bip32PublicKeyHex; } export interface SerializableInMemoryKeyAgentData extends SerializableKeyAgentDataBase { @@ -123,13 +123,13 @@ export type SerializableKeyAgentData = export type LedgerTransportType = TransportWebHID | TransportNodeHid; export interface KeyPair { - skey: Cardano.Bip32PrivateKey; - vkey: Cardano.Bip32PublicKey; + skey: Crypto.Bip32PrivateKeyHex; + vkey: Crypto.Bip32PublicKeyHex; } export interface Ed25519KeyPair { - skey: Cardano.Ed25519PrivateKey; - vkey: Cardano.Ed25519PublicKey; + skey: Crypto.Ed25519PrivateNormalKeyHex | Crypto.Ed25519PrivateExtendedKeyHex; + vkey: Crypto.Ed25519PublicKeyHex; } /** @@ -146,7 +146,8 @@ export interface KeyAgent { get accountIndex(): number; get serializableData(): SerializableKeyAgentData; get knownAddresses(): GroupedAddress[]; - get extendedAccountPublicKey(): Cardano.Bip32PublicKey; + get extendedAccountPublicKey(): Crypto.Bip32PublicKeyHex; + get bip32Ed25519(): Crypto.Bip32Ed25519; /** * @throws AuthenticationError */ @@ -158,7 +159,7 @@ export interface KeyAgent { /** * @throws AuthenticationError */ - derivePublicKey(derivationPath: AccountKeyDerivationPath): Promise; + derivePublicKey(derivationPath: AccountKeyDerivationPath): Promise; /** * @throws AuthenticationError */ @@ -166,13 +167,14 @@ export interface KeyAgent { /** * @throws AuthenticationError */ - exportRootPrivateKey(): Promise; + exportRootPrivateKey(): Promise; } export type AsyncKeyAgent = Pick & { knownAddresses$: Observable; getChainId(): Promise; - getExtendedAccountPublicKey(): Promise; + getBip32Ed25519(): Promise; + getExtendedAccountPublicKey(): Promise; } & Shutdown; /** @@ -182,12 +184,12 @@ export type TransactionSignerResult = { /** * The public key matching the private key that generate the signature. */ - pubKey: Cardano.Ed25519PublicKey; + pubKey: Crypto.Ed25519PublicKeyHex; /** * The transaction signature. */ - signature: Cardano.Ed25519Signature; + signature: Crypto.Ed25519SignatureHex; }; /** diff --git a/packages/key-management/src/util/createAsyncKeyAgent.ts b/packages/key-management/src/util/createAsyncKeyAgent.ts index d23add2336c..444414afe6c 100644 --- a/packages/key-management/src/util/createAsyncKeyAgent.ts +++ b/packages/key-management/src/util/createAsyncKeyAgent.ts @@ -13,6 +13,7 @@ export const createAsyncKeyAgent = (keyAgent: KeyAgent, onShutdown?: () => void) return address; }, derivePublicKey: keyAgent.derivePublicKey.bind(keyAgent), + getBip32Ed25519: () => Promise.resolve(keyAgent.bip32Ed25519), getChainId: () => Promise.resolve(keyAgent.chainId), getExtendedAccountPublicKey: () => Promise.resolve(keyAgent.extendedAccountPublicKey), knownAddresses$, diff --git a/packages/key-management/src/util/key.ts b/packages/key-management/src/util/key.ts index 4f5772d9053..e1529044078 100644 --- a/packages/key-management/src/util/key.ts +++ b/packages/key-management/src/util/key.ts @@ -1,5 +1,5 @@ +import * as Crypto from '@cardano-sdk/crypto'; import { AccountKeyDerivationPath, CardanoKeyConst, Ed25519KeyPair, KeyPair, KeyRole } from '../types'; -import { CML, Cardano, util } from '@cardano-sdk/core'; export const harden = (num: number): number => 0x80_00_00_00 + num; @@ -8,29 +8,27 @@ export const STAKE_KEY_DERIVATION_PATH: AccountKeyDerivationPath = { role: KeyRole.Stake }; -export const toEd25519KeyPair = (bip32KeyPair: KeyPair): Ed25519KeyPair => { - const pubKeyBytes = Buffer.from(bip32KeyPair.vkey, 'hex'); - const cmlPubKey = CML.Bip32PublicKey.from_bytes(pubKeyBytes); - const vkey = Cardano.Ed25519PublicKey.fromHexBlob(util.bytesToHex(cmlPubKey.to_raw_key().as_bytes())); - const prvKeyBytes = Buffer.from(bip32KeyPair.skey, 'hex'); - const cmlPrvKey = CML.Bip32PrivateKey.from_bytes(prvKeyBytes); - const skey = Cardano.Ed25519PrivateKey.fromHexBlob(util.bytesToHex(cmlPrvKey.to_raw_key().as_bytes())); - return { - skey, - vkey - }; -}; +export const toEd25519KeyPair = async ( + bip32KeyPair: KeyPair, + provider: Crypto.Bip32Ed25519 +): Promise => ({ + skey: await provider.getRawPrivateKey(bip32KeyPair.skey), + vkey: await provider.getRawPublicKey(bip32KeyPair.vkey) +}); export interface DeriveAccountPrivateKeyProps { - rootPrivateKey: CML.Bip32PrivateKey; + rootPrivateKey: Crypto.Bip32PrivateKeyHex; accountIndex: number; + bip32Ed25519: Crypto.Bip32Ed25519; } -export const deriveAccountPrivateKey = ({ +export const deriveAccountPrivateKey = async ({ rootPrivateKey, - accountIndex -}: DeriveAccountPrivateKeyProps): CML.Bip32PrivateKey => - rootPrivateKey - .derive(harden(CardanoKeyConst.PURPOSE)) - .derive(harden(CardanoKeyConst.COIN_TYPE)) - .derive(harden(accountIndex)); + accountIndex, + bip32Ed25519 +}: DeriveAccountPrivateKeyProps): Promise => + await bip32Ed25519.derivePrivateKey(rootPrivateKey, [ + harden(CardanoKeyConst.PURPOSE), + harden(CardanoKeyConst.COIN_TYPE), + harden(accountIndex) + ]); diff --git a/packages/key-management/src/util/mapHardwareSigningData.ts b/packages/key-management/src/util/mapHardwareSigningData.ts index 85239026a23..7e2a712d464 100644 --- a/packages/key-management/src/util/mapHardwareSigningData.ts +++ b/packages/key-management/src/util/mapHardwareSigningData.ts @@ -3,8 +3,9 @@ /* eslint-disable sonarjs/cognitive-complexity, max-depth, max-statements, complexity */ import * as ledger from '@cardano-foundation/ledgerjs-hw-app-cardano'; import * as trezor from 'trezor-connect'; -import { BIP32Path, CardanoKeyConst, GroupedAddress } from '../types'; +import { BIP32Path } from '@cardano-sdk/crypto'; import { CML, Cardano, cmlToCore } from '@cardano-sdk/core'; +import { CardanoKeyConst, GroupedAddress } from '../types'; import { HwMappingError } from '../errors'; import { ManagedFreeableScope, isNotNil, usingAutoFree } from '@cardano-sdk/util'; import { STAKE_KEY_DERIVATION_PATH, harden } from './key'; diff --git a/packages/key-management/src/util/ownSignatureKeyPaths.ts b/packages/key-management/src/util/ownSignatureKeyPaths.ts index 5a4c6c9a65a..1a66843dab8 100644 --- a/packages/key-management/src/util/ownSignatureKeyPaths.ts +++ b/packages/key-management/src/util/ownSignatureKeyPaths.ts @@ -20,7 +20,7 @@ const getStakingKeyPaths = ( const uniqueAccounts = uniqBy(groupedAddresses, 'rewardAccount'); for (const account of uniqueAccounts) { - const stakeKeyHash = Cardano.Ed25519KeyHash.fromRewardAccount(account.rewardAccount); + const stakeKeyHash = Cardano.RewardAccount.toHash(account.rewardAccount); const poolId = Cardano.PoolId.fromKeyHash(stakeKeyHash); if (!account.stakeKeyDerivationPath) continue; diff --git a/packages/key-management/src/util/stubSignTransaction.ts b/packages/key-management/src/util/stubSignTransaction.ts index 97c3a087f17..5a8801c07f7 100644 --- a/packages/key-management/src/util/stubSignTransaction.ts +++ b/packages/key-management/src/util/stubSignTransaction.ts @@ -1,11 +1,13 @@ +import * as Crypto from '@cardano-sdk/crypto'; import { Cardano } from '@cardano-sdk/core'; import { GroupedAddress, SignTransactionOptions, TransactionSigner } from '../types'; import { deepEquals } from '@cardano-sdk/util'; import { ownSignatureKeyPaths } from './ownSignatureKeyPaths'; + import uniqWith from 'lodash/uniqWith'; const randomHexChar = () => Math.floor(Math.random() * 16).toString(16); -const randomPublicKey = () => Cardano.Ed25519PublicKey(Array.from({ length: 64 }).map(randomHexChar).join('')); +const randomPublicKey = () => Crypto.Ed25519PublicKeyHex(Array.from({ length: 64 }).map(randomHexChar).join('')); export const stubSignTransaction = async ( txBody: Cardano.TxBody, @@ -14,7 +16,7 @@ export const stubSignTransaction = async ( extraSigners?: TransactionSigner[], { additionalKeyPaths = [] }: SignTransactionOptions = {} ): Promise => { - const mockSignature = Cardano.Ed25519Signature( + const mockSignature = Crypto.Ed25519SignatureHex( // eslint-disable-next-line max-len 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff' ); diff --git a/packages/key-management/test/InMemoryKeyAgent.test.ts b/packages/key-management/test/InMemoryKeyAgent.test.ts index 0d3ca6b0793..e65a418f5c1 100644 --- a/packages/key-management/test/InMemoryKeyAgent.test.ts +++ b/packages/key-management/test/InMemoryKeyAgent.test.ts @@ -1,3 +1,4 @@ +import * as Crypto from '@cardano-sdk/crypto'; import { AddressType, InMemoryKeyAgent, KeyRole, SerializableInMemoryKeyAgentData, util } from '../src'; import { CML, Cardano } from '@cardano-sdk/core'; import { HexBlob } from '@cardano-sdk/util'; @@ -11,6 +12,7 @@ describe('InMemoryKeyAgent', () => { let getPassword: jest.Mock; let inputResolver: jest.Mocked; let mnemonicWords: string[]; + const bip32Ed25519 = new Crypto.CmlBip32Ed25519(CML); beforeEach(async () => { mnemonicWords = util.generateMnemonicWords(); @@ -22,7 +24,7 @@ describe('InMemoryKeyAgent', () => { getPassword, mnemonicWords }, - { inputResolver, logger: dummyLogger } + { bip32Ed25519, inputResolver, logger: dummyLogger } ); }); @@ -45,10 +47,10 @@ describe('InMemoryKeyAgent', () => { { chainId: Cardano.ChainIds.Preview, getPassword, - mnemonic2ndFactorPassphrase: Buffer.from('passphrase'), + mnemonic2ndFactorPassphrase: 'passphrase', mnemonicWords }, - { inputResolver, logger: dummyLogger } + { bip32Ed25519, inputResolver, logger: dummyLogger } ); expect(await saferKeyAgent.exportRootPrivateKey()).not.toEqual(await keyAgent.exportRootPrivateKey()); }); @@ -147,21 +149,17 @@ describe('InMemoryKeyAgent', () => { accountIndex: 0, chainId: Cardano.ChainIds.Preview, encryptedRootPrivateKeyBytes: [...Buffer.from(yoroiEncryptedRootPrivateKeyHex, 'hex')], - extendedAccountPublicKey: Cardano.Bip32PublicKey( - Buffer.from( - util - .deriveAccountPrivateKey({ - accountIndex: 0, - rootPrivateKey: CML.Bip32PrivateKey.from_bytes(Buffer.from(yoroiRootPrivateKeyHex, 'hex')) - }) - .to_public() - .as_bytes() - ).toString('hex') + extendedAccountPublicKey: await bip32Ed25519.getBip32PublicKey( + await util.deriveAccountPrivateKey({ + accountIndex: 0, + bip32Ed25519, + rootPrivateKey: Crypto.Bip32PrivateKeyHex(yoroiRootPrivateKeyHex) + }) ), getPassword, knownAddresses: [] }, - { inputResolver, logger: dummyLogger } + { bip32Ed25519, inputResolver, logger: dummyLogger } ); const exportedPrivateKeyHex = await keyAgentFromEncryptedKey.exportRootPrivateKey(); expect(exportedPrivateKeyHex).toEqual(yoroiRootPrivateKeyHex); @@ -174,7 +172,7 @@ describe('InMemoryKeyAgent', () => { getPassword, mnemonicWords: yoroiMnemonic }, - { inputResolver, logger: dummyLogger } + { bip32Ed25519, inputResolver, logger: dummyLogger } ); const exportedPrivateKeyHex = await keyAgentFromMnemonic.exportRootPrivateKey(); expect(exportedPrivateKeyHex).toEqual(yoroiRootPrivateKeyHex); @@ -192,7 +190,7 @@ describe('InMemoryKeyAgent', () => { getPassword, mnemonicWords: michaelMnemonic }, - { inputResolver, logger: dummyLogger } + { bip32Ed25519, inputResolver, logger: dummyLogger } ); ownSignatureKeyPaths.mockResolvedValue([{ index: 0, type: KeyRole.External }]); @@ -201,7 +199,7 @@ describe('InMemoryKeyAgent', () => { hash: Cardano.TransactionId('0000000000000000000000000000000000000000000000000000000000000000') }); expect( - signature.has(Cardano.Ed25519PublicKey('0b1c96fad4179d7910bd9485ac28c4c11368c83d18d01b29d4cf84d8ff6a06c4')) + signature.has(Crypto.Ed25519PublicKeyHex('0b1c96fad4179d7910bd9485ac28c4c11368c83d18d01b29d4cf84d8ff6a06c4')) ).toBe(true); }); }); @@ -246,22 +244,18 @@ describe('InMemoryKeyAgent', () => { accountIndex: 0, chainId: Cardano.ChainIds.Preview, encryptedRootPrivateKeyBytes: [...Buffer.from(daedelusEncryptedRootPrivateKeyHex, 'hex')], - extendedAccountPublicKey: Cardano.Bip32PublicKey( - Buffer.from( - util - .deriveAccountPrivateKey({ - accountIndex: 0, - rootPrivateKey: CML.Bip32PrivateKey.from_bytes(Buffer.from(daedalusRootPrivateKeyHex, 'hex')) - }) - .to_public() - .as_bytes() - ).toString('hex') + extendedAccountPublicKey: await bip32Ed25519.getBip32PublicKey( + await util.deriveAccountPrivateKey({ + accountIndex: 0, + bip32Ed25519, + rootPrivateKey: Crypto.Bip32PrivateKeyHex(daedalusRootPrivateKeyHex) + }) ), // daedelus enforces min length of 10 getPassword: jest.fn().mockResolvedValue(Buffer.from('nMmys*X002')), knownAddresses: [] }, - { inputResolver, logger: dummyLogger } + { bip32Ed25519, inputResolver, logger: dummyLogger } ); const derivedAddress = await keyAgentFromEncryptedKey.deriveAddress({ index: 1, @@ -277,7 +271,7 @@ describe('InMemoryKeyAgent', () => { getPassword, mnemonicWords: daedelusMnemonic24 }, - { inputResolver, logger: dummyLogger } + { bip32Ed25519, inputResolver, logger: dummyLogger } ); const derivedAddress = await keyAgentFromMnemonic.deriveAddress({ index: 1, diff --git a/packages/key-management/test/KeyAgentBase.test.ts b/packages/key-management/test/KeyAgentBase.test.ts index 1452efb4a83..0007690bb4a 100644 --- a/packages/key-management/test/KeyAgentBase.test.ts +++ b/packages/key-management/test/KeyAgentBase.test.ts @@ -1,20 +1,19 @@ /* eslint-disable sonarjs/no-duplicate-string */ -import { - AccountKeyDerivationPath, - AddressType, - KeyAgentBase, - KeyAgentType, - KeyRole, - SerializableInMemoryKeyAgentData -} from '../src'; +import * as Crypto from '@cardano-sdk/crypto'; +import { AddressType, KeyAgentBase, KeyAgentType, KeyRole, SerializableInMemoryKeyAgentData } from '../src'; import { CML, Cardano } from '@cardano-sdk/core'; import { dummyLogger } from 'ts-log'; const ACCOUNT_INDEX = 1; +const bip32Ed25519 = new Crypto.CmlBip32Ed25519(CML); class MockKeyAgent extends KeyAgentBase { constructor(data: SerializableInMemoryKeyAgentData) { - super(data, { inputResolver: { resolveInputAddress: () => Promise.resolve(null) }, logger: dummyLogger }); + super(data, { + bip32Ed25519, + inputResolver: { resolveInputAddress: () => Promise.resolve(null) }, + logger: dummyLogger + }); } serializableDataImpl = jest.fn(); @@ -23,21 +22,18 @@ class MockKeyAgent extends KeyAgentBase { signTransaction = jest.fn(); signVotingMetadata = jest.fn(); exportExtendedKeyPair = jest.fn(); - deriveCmlPublicKeyPublic(derivationPath: AccountKeyDerivationPath) { - return this.deriveCmlPublicKey(derivationPath); - } } describe('KeyAgentBase', () => { let keyAgent: MockKeyAgent; - beforeAll(() => { + beforeEach(() => { keyAgent = new MockKeyAgent({ __typename: KeyAgentType.InMemory, accountIndex: ACCOUNT_INDEX, chainId: Cardano.ChainIds.Preview, encryptedRootPrivateKeyBytes: [], - extendedAccountPublicKey: Cardano.Bip32PublicKey( + extendedAccountPublicKey: Crypto.Bip32PublicKeyHex( // eslint-disable-next-line max-len 'fc5ab25e830b67c47d0a17411bf7fdabf711a597fb6cf04102734b0a2934ceaaa65ff5e7c52498d52c07b8ddfcd436fc2b4d2775e2984a49d0c79f65ceee4779' ), @@ -79,8 +75,4 @@ describe('KeyAgentBase', () => { const stakePublicKey = await keyAgent.derivePublicKey({ index: 1, role: KeyRole.Stake }); expect(typeof stakePublicKey).toBe('string'); }); - - test('deriveCMLPublicKey', async () => { - expect(await keyAgent.deriveCmlPublicKeyPublic({ index: 0, role: KeyRole.External })).toBeInstanceOf(CML.PublicKey); - }); }); diff --git a/packages/key-management/test/mocks/mockKeyAgentDependencies.ts b/packages/key-management/test/mocks/mockKeyAgentDependencies.ts index f3489402a09..94f9fb336a1 100644 --- a/packages/key-management/test/mocks/mockKeyAgentDependencies.ts +++ b/packages/key-management/test/mocks/mockKeyAgentDependencies.ts @@ -1,7 +1,10 @@ +import { CML } from '@cardano-sdk/core'; +import { CmlBip32Ed25519 } from '@cardano-sdk/crypto'; import { KeyAgentDependencies } from '../../src/'; import { dummyLogger } from 'ts-log'; export const mockKeyAgentDependencies = (): jest.Mocked => ({ + bip32Ed25519: new CmlBip32Ed25519(CML), inputResolver: { resolveInputAddress: jest.fn().mockResolvedValue(null) }, diff --git a/packages/key-management/test/restoreKeyAgent.test.ts b/packages/key-management/test/restoreKeyAgent.test.ts index 210be572a59..5d9231f0015 100644 --- a/packages/key-management/test/restoreKeyAgent.test.ts +++ b/packages/key-management/test/restoreKeyAgent.test.ts @@ -1,3 +1,4 @@ +import * as Crypto from '@cardano-sdk/crypto'; import { AddressType, CommunicationType, @@ -9,13 +10,17 @@ import { SerializableTrezorKeyAgentData, restoreKeyAgent } from '../src'; -import { Cardano } from '@cardano-sdk/core'; +import { CML, Cardano } from '@cardano-sdk/core'; import { InvalidSerializableDataError } from '../src/errors'; import { STAKE_KEY_DERIVATION_PATH } from '../src/util'; import { dummyLogger } from 'ts-log'; describe('KeyManagement/restoreKeyAgent', () => { - const dependencies: KeyAgentDependencies = { inputResolver: { resolveInputAddress: jest.fn() }, logger: dummyLogger }; + const dependencies: KeyAgentDependencies = { + bip32Ed25519: new Crypto.CmlBip32Ed25519(CML), + inputResolver: { resolveInputAddress: jest.fn() }, + logger: dummyLogger + }; describe('InMemoryKeyAgent', () => { const encryptedRootPrivateKeyBytes = [ @@ -32,7 +37,7 @@ describe('KeyManagement/restoreKeyAgent', () => { 'addr1qx52knza2h5x090n4a5r7yraz3pwcamk9ppvuh7e26nfks7pnmhxqavtqy02zezklh27jt9r6z62sav3mugappdc7xnskxy2pn' ); - const extendedAccountPublicKey = Cardano.Bip32PublicKey( + const extendedAccountPublicKey = Crypto.Bip32PublicKeyHex( // eslint-disable-next-line max-len '6199186adb51974690d7247d2646097d2c62763b767b528816fb7ed3f9f55d396199186adb51974690d7247d2646097d2c62763b767b528816fb7ed3f9f55d39' ); @@ -112,7 +117,7 @@ describe('KeyManagement/restoreKeyAgent', () => { accountIndex: 0, chainId: Cardano.ChainIds.LegacyTestnet, communicationType: CommunicationType.Node, - extendedAccountPublicKey: Cardano.Bip32PublicKey( + extendedAccountPublicKey: Crypto.Bip32PublicKeyHex( // eslint-disable-next-line max-len 'fc5ab25e830b67c47d0a17411bf7fdabf711a597fb6cf04102734b0a2934ceaaa65ff5e7c52498d52c07b8ddfcd436fc2b4d2775e2984a49d0c79f65ceee4779' ), @@ -142,7 +147,7 @@ describe('KeyManagement/restoreKeyAgent', () => { __typename: KeyAgentType.Trezor, accountIndex: 0, chainId: Cardano.ChainIds.LegacyTestnet, - extendedAccountPublicKey: Cardano.Bip32PublicKey( + extendedAccountPublicKey: Crypto.Bip32PublicKeyHex( // eslint-disable-next-line max-len 'fc5ab25e830b67c47d0a17411bf7fdabf711a597fb6cf04102734b0a2934ceaaa65ff5e7c52498d52c07b8ddfcd436fc2b4d2775e2984a49d0c79f65ceee4779' ), diff --git a/packages/key-management/test/util/createAsyncKeyAgent.test.ts b/packages/key-management/test/util/createAsyncKeyAgent.test.ts index 5934cd9e017..6495e0673d8 100644 --- a/packages/key-management/test/util/createAsyncKeyAgent.test.ts +++ b/packages/key-management/test/util/createAsyncKeyAgent.test.ts @@ -1,5 +1,6 @@ +import * as Crypto from '@cardano-sdk/crypto'; import { AsyncKeyAgent, InMemoryKeyAgent, KeyAgent, util } from '../../src'; -import { Cardano } from '@cardano-sdk/core'; +import { CML, Cardano } from '@cardano-sdk/core'; import { HexBlob } from '@cardano-sdk/util'; import { dummyLogger } from 'ts-log'; import { firstValueFrom } from 'rxjs'; @@ -20,7 +21,7 @@ describe('createAsyncKeyAgent maps KeyAgent to AsyncKeyAgent', () => { getPassword, mnemonicWords }, - { inputResolver, logger: dummyLogger } + { bip32Ed25519: new Crypto.CmlBip32Ed25519(CML), inputResolver, logger: dummyLogger } ); asyncKeyAgent = util.createAsyncKeyAgent(keyAgent); }); diff --git a/packages/key-management/test/util/ownSignaturePaths.test.ts b/packages/key-management/test/util/ownSignaturePaths.test.ts index c008bf69f5e..3f07d588371 100644 --- a/packages/key-management/test/util/ownSignaturePaths.test.ts +++ b/packages/key-management/test/util/ownSignaturePaths.test.ts @@ -32,8 +32,8 @@ describe('KeyManagement.util.ownSignaturePaths', () => { 'addr_test1qz2fxv2umyhttkxyxp8x0dlpdt3k6cwng5pxj3jhsydzer3jcu5d8ps7zex2k2xt3uqxgjqnnj83ws8lhrn648jjxtwq2ytjqp' ); - const ownStakeKeyHash = Cardano.Ed25519KeyHash.fromRewardAccount(ownRewardAccount); - const otherStakeKeyHash = Cardano.Ed25519KeyHash.fromRewardAccount(otherRewardAccount); + const ownStakeKeyHash = Cardano.RewardAccount.toHash(ownRewardAccount); + const otherStakeKeyHash = Cardano.RewardAccount.toHash(otherRewardAccount); const knownAddress1 = createGroupedAddress(address1, ownRewardAccount, AddressType.External, 0, stakeKeyPath); diff --git a/packages/ogmios/package.json b/packages/ogmios/package.json index 6a4982caa9a..11c92fd1d68 100644 --- a/packages/ogmios/package.json +++ b/packages/ogmios/package.json @@ -68,6 +68,7 @@ "dependencies": { "@cardano-ogmios/client": "5.5.7", "@cardano-sdk/core": "^0.7.0", + "@cardano-sdk/crypto": "^0.1.0", "@cardano-sdk/util": "^0.7.0", "buffer": "5.7.1", "fraction.js": "^4.2.0", diff --git a/packages/ogmios/src/ogmiosToCore/block.ts b/packages/ogmios/src/ogmiosToCore/block.ts index 7a19d049447..09a150b9c96 100644 --- a/packages/ogmios/src/ogmiosToCore/block.ts +++ b/packages/ogmios/src/ogmiosToCore/block.ts @@ -10,6 +10,7 @@ import { isShelleyBlock } from '@cardano-ogmios/client'; +import * as Crypto from '@cardano-sdk/crypto'; import { BlockAndKind, BlockKind, CommonBlock, OgmiosBlockType } from './types'; import { Cardano } from '@cardano-sdk/core'; import { mapByronBlockBody, mapCommonBlockBody } from './tx'; @@ -83,8 +84,8 @@ const mapCommonFees = (block: CommonBlock): Cardano.Lovelace => const mapCommonVrf = (block: CommonBlock): Cardano.VrfVkBech32 => Cardano.VrfVkBech32FromBase64(block.header.issuerVrf); // SlotLeader is the producer pool id. It can be calculated from the issuer verification key // which is actually the cold verification key -const mapCommonSlotLeader = (block: CommonBlock): Cardano.Ed25519PublicKey => - Cardano.Ed25519PublicKey(block.header.issuerVk); +const mapCommonSlotLeader = (block: CommonBlock): Crypto.Ed25519PublicKeyHex => + Crypto.Ed25519PublicKeyHex(block.header.issuerVk); const mapStandardBlockHeader = (block: Schema.StandardBlock) => ({ blockNo: Cardano.BlockNo(mapBlockHeight(block)), diff --git a/packages/ogmios/src/ogmiosToCore/tx.ts b/packages/ogmios/src/ogmiosToCore/tx.ts index e011f7f119b..abfd027b382 100644 --- a/packages/ogmios/src/ogmiosToCore/tx.ts +++ b/packages/ogmios/src/ogmiosToCore/tx.ts @@ -1,4 +1,5 @@ /* eslint-disable max-len */ +import * as Crypto from '@cardano-sdk/crypto'; import { BYRON_TX_FEE_COEFFICIENT, BYRON_TX_FEE_CONSTANT, @@ -14,7 +15,7 @@ import { isShelleyTx, isStartsAt } from './util'; -import { Base64Blob, Hash28ByteBase16, Hash32ByteBase16, HexBlob } from '@cardano-sdk/util'; +import { Base64Blob, HexBlob } from '@cardano-sdk/util'; import { BlockKind, CommonBlock } from './types'; import { Cardano, @@ -60,12 +61,12 @@ const mapPoolParameters = (poolParameters: Schema.PoolParameters): Cardano.PoolP margin: mapMargin(poolParameters.margin), metadataJson: poolParameters.metadata ? { - hash: Hash32ByteBase16(poolParameters.metadata.hash), + hash: Crypto.Hash32ByteBase16(poolParameters.metadata.hash), url: poolParameters.metadata.url } : undefined, owners: poolParameters.owners.map((ownerKeyHash) => - createRewardAccount(Cardano.Ed25519KeyHash(ownerKeyHash), addressNetworkId(rewardAccount)) + createRewardAccount(Crypto.Ed25519KeyHashHex(ownerKeyHash), addressNetworkId(rewardAccount)) ), relays: poolParameters.relays.map(mapRelay), rewardAccount, @@ -78,19 +79,19 @@ const mapCertificate = (certificate: Schema.Certificate): Cardano.Certificate => return { __typename: Cardano.CertificateType.StakeDelegation, poolId: Cardano.PoolId(certificate.stakeDelegation.delegatee), - stakeKeyHash: Cardano.Ed25519KeyHash(certificate.stakeDelegation.delegator) + stakeKeyHash: Crypto.Ed25519KeyHashHex(certificate.stakeDelegation.delegator) }; } if ('stakeKeyRegistration' in certificate) { return { __typename: Cardano.CertificateType.StakeKeyRegistration, - stakeKeyHash: Cardano.Ed25519KeyHash(certificate.stakeKeyRegistration) + stakeKeyHash: Crypto.Ed25519KeyHashHex(certificate.stakeKeyRegistration) }; } if ('stakeKeyDeregistration' in certificate) { return { __typename: Cardano.CertificateType.StakeKeyDeregistration, - stakeKeyHash: Cardano.Ed25519KeyHash(certificate.stakeKeyDeregistration) + stakeKeyHash: Crypto.Ed25519KeyHashHex(certificate.stakeKeyDeregistration) }; } if ('poolRegistration' in certificate) { @@ -109,9 +110,9 @@ const mapCertificate = (certificate: Schema.Certificate): Cardano.Certificate => if ('genesisDelegation' in certificate) { return { __typename: Cardano.CertificateType.GenesisKeyDelegation, - genesisDelegateHash: Hash28ByteBase16(certificate.genesisDelegation.delegateKeyHash), - genesisHash: Hash28ByteBase16(certificate.genesisDelegation.verificationKeyHash), - vrfKeyHash: Hash32ByteBase16(certificate.genesisDelegation.vrfVerificationKeyHash) + genesisDelegateHash: Crypto.Hash28ByteBase16(certificate.genesisDelegation.delegateKeyHash), + genesisHash: Crypto.Hash28ByteBase16(certificate.genesisDelegation.verificationKeyHash), + vrfKeyHash: Crypto.Hash32ByteBase16(certificate.genesisDelegation.vrfVerificationKeyHash) }; } if ('moveInstantaneousRewards' in certificate) { @@ -137,7 +138,7 @@ export const nativeScript = (script: Schema.ScriptNative): Cardano.NativeScript if (typeof script === 'string') { coreScript = { __type: Cardano.ScriptType.Native, - keyHash: Cardano.Ed25519KeyHash(script), + keyHash: Crypto.Ed25519KeyHashHex(script), kind: Cardano.NativeScriptKind.RequireSignature }; } else if (isRequireAllOf(script)) { @@ -214,8 +215,8 @@ const mapBootstrapWitness = (b: Schema.BootstrapWitness): Cardano.BootstrapWitne // Based on the Ogmios maintainer answer https://github.com/CardanoSolutions/ogmios/discussions/285#discussioncomment-4271726 addressAttributes: b.addressAttributes ? Base64Blob(b.addressAttributes) : undefined, chainCode: b.chainCode ? HexBlob(b.chainCode) : undefined, - key: Cardano.Ed25519PublicKey(b.key!), - signature: Cardano.Ed25519Signature(HexBlob.fromBase64(b.signature!).toString()) + key: Crypto.Ed25519PublicKeyHex(b.key!), + signature: Crypto.Ed25519SignatureHex(HexBlob.fromBase64(b.signature!).toString()) }); const mapRedeemer = (key: string, redeemer: Schema.Redeemer): Cardano.Redeemer => { @@ -241,7 +242,7 @@ const mapAuxiliaryData = (data: Schema.AuxiliaryData | null): Cardano.AuxiliaryD : undefined, scripts: data.body.scripts ? data.body.scripts.map(mapScript) : undefined }, - hash: Hash32ByteBase16(data.hash) + hash: Crypto.Hash32ByteBase16(data.hash) }; }; @@ -257,7 +258,7 @@ const mapInlineDatum = (datum: Schema.TxOut['datum']) => { const mapDatumHash = (datum: Schema.TxOut['datumHash']) => { if (!datum) return; - return Hash32ByteBase16(datum); + return Crypto.Hash32ByteBase16(datum); }; const mapTxOut = (txOut: Schema.TxOut): Cardano.TxOut => ({ @@ -278,9 +279,11 @@ const mapMint = (tx: Schema.TxMary): Cardano.TokenMap | undefined => { return new Map(Object.entries(tx.body.mint.assets).map(([key, value]) => [Cardano.AssetId(key), value])); }; -const mapScriptIntegrityHash = ({ body: { scriptIntegrityHash } }: Schema.TxAlonzo): Hash32ByteBase16 | undefined => { +const mapScriptIntegrityHash = ({ + body: { scriptIntegrityHash } +}: Schema.TxAlonzo): Crypto.Hash32ByteBase16 | undefined => { if (scriptIntegrityHash === null) return undefined; - return Hash32ByteBase16(scriptIntegrityHash); + return Crypto.Hash32ByteBase16(scriptIntegrityHash); }; const mapValidityInterval = ({ @@ -301,7 +304,7 @@ const mapCommonTx = (tx: CommonBlock['body'][0], kind: BlockKind): Cardano.Tx => mint: isMaryOrAbove(kind) ? mapMint(tx as Schema.TxMary) : undefined, outputs: tx.body.outputs.map(mapTxOut), requiredExtraSignatures: isAlonzoOrAbove(kind) - ? (tx as Schema.TxAlonzo).body.requiredExtraSignatures.map(Cardano.Ed25519KeyHash) + ? (tx as Schema.TxAlonzo).body.requiredExtraSignatures.map(Crypto.Ed25519KeyHashHex) : undefined, scriptIntegrityHash: isAlonzoOrAbove(kind) ? mapScriptIntegrityHash(tx as Schema.TxAlonzo) : undefined, validityInterval: isShelleyTx(kind) @@ -324,8 +327,8 @@ const mapCommonTx = (tx: CommonBlock['body'][0], kind: BlockKind): Cardano.Tx => scripts: [...Object.values(tx.witness.scripts).map(mapScript)], signatures: new Map( Object.entries(tx.witness.signatures).map(([key, value]) => [ - Cardano.Ed25519PublicKey(key), - Cardano.Ed25519Signature(HexBlob.fromBase64(value).toString()) + Crypto.Ed25519PublicKeyHex(key), + Crypto.Ed25519SignatureHex(HexBlob.fromBase64(value).toString()) ]) ) } diff --git a/packages/projection/package.json b/packages/projection/package.json index 3a3f504ca83..27c74af7b64 100644 --- a/packages/projection/package.json +++ b/packages/projection/package.json @@ -49,6 +49,7 @@ }, "dependencies": { "@cardano-sdk/core": "^0.7.0", + "@cardano-sdk/crypto": "^0.1.0", "@cardano-sdk/util": "^0.7.0", "@cardano-sdk/util-rxjs": "^0.4.3", "lodash": "^4.17.21", diff --git a/packages/projection/src/operators/certificates/withStakeKeys.ts b/packages/projection/src/operators/certificates/withStakeKeys.ts index 341975b3c0f..864a04e22b9 100644 --- a/packages/projection/src/operators/certificates/withStakeKeys.ts +++ b/packages/projection/src/operators/certificates/withStakeKeys.ts @@ -1,11 +1,12 @@ +import * as Crypto from '@cardano-sdk/crypto'; import { Cardano } from '@cardano-sdk/core'; import { WithCertificates } from './withCertificates'; import { unifiedProjectorOperator } from '../utils'; export interface WithStakeKeys { stakeKeys: { - register: Set; - deregister: Set; + register: Set; + deregister: Set; }; } @@ -20,8 +21,8 @@ export interface WithStakeKeys { * ignoring **when** they were registered or unregistered. */ export const withStakeKeys = unifiedProjectorOperator((evt) => { - const register = new Set(); - const deregister = new Set(); + const register = new Set(); + const deregister = new Set(); for (const { certificate } of evt.certificates) switch (certificate.__typename) { case Cardano.CertificateType.StakeKeyRegistration: diff --git a/packages/projection/src/sinks/inMemory/types.ts b/packages/projection/src/sinks/inMemory/types.ts index a91074cedd1..451aadc8314 100644 --- a/packages/projection/src/sinks/inMemory/types.ts +++ b/packages/projection/src/sinks/inMemory/types.ts @@ -1,8 +1,9 @@ import { Cardano } from '@cardano-sdk/core'; +import { Ed25519KeyHashHex } from '@cardano-sdk/crypto'; import { PoolRetirement, PoolUpdate } from '../../operators'; export type InMemoryStore = { - stakeKeys: Set; + stakeKeys: Set; stakePools: Map< Cardano.PoolId, { diff --git a/packages/projection/test/operators/certificates/withStakeKeys.test.ts b/packages/projection/test/operators/certificates/withStakeKeys.test.ts index 313c2fed861..df81080d89f 100644 --- a/packages/projection/test/operators/certificates/withStakeKeys.test.ts +++ b/packages/projection/test/operators/certificates/withStakeKeys.test.ts @@ -1,3 +1,4 @@ +import * as Crypto from '@cardano-sdk/crypto'; import { Cardano } from '@cardano-sdk/core'; import { CertificatePointer, WithCertificates, withStakeKeys } from '../../../src/operators'; import { UnifiedProjectorEvent, WithBlock } from '../../../src'; @@ -10,14 +11,14 @@ describe('withStakeKeys', () => { { certificate: { __typename: Cardano.CertificateType.StakeKeyRegistration, - stakeKeyHash: Cardano.Ed25519KeyHash('3b62970858d61cf667701c1f34abef41659516b191d7d374e8b0857b') + stakeKeyHash: Crypto.Ed25519KeyHashHex('3b62970858d61cf667701c1f34abef41659516b191d7d374e8b0857b') }, pointer: {} as CertificatePointer }, { certificate: { __typename: Cardano.CertificateType.StakeKeyDeregistration, - stakeKeyHash: Cardano.Ed25519KeyHash('3b62970858d61cf667701c1f34abef41659516b191d7d374e8b0857c') + stakeKeyHash: Crypto.Ed25519KeyHashHex('3b62970858d61cf667701c1f34abef41659516b191d7d374e8b0857c') }, pointer: {} as CertificatePointer } @@ -36,14 +37,14 @@ describe('withStakeKeys', () => { { certificate: { __typename: Cardano.CertificateType.StakeKeyRegistration, - stakeKeyHash: Cardano.Ed25519KeyHash('3b62970858d61cf667701c1f34abef41659516b191d7d374e8b0857b') + stakeKeyHash: Crypto.Ed25519KeyHashHex('3b62970858d61cf667701c1f34abef41659516b191d7d374e8b0857b') }, pointer: {} as CertificatePointer }, { certificate: { __typename: Cardano.CertificateType.StakeKeyDeregistration, - stakeKeyHash: Cardano.Ed25519KeyHash('3b62970858d61cf667701c1f34abef41659516b191d7d374e8b0857b') + stakeKeyHash: Crypto.Ed25519KeyHashHex('3b62970858d61cf667701c1f34abef41659516b191d7d374e8b0857b') }, pointer: {} as CertificatePointer } @@ -62,14 +63,14 @@ describe('withStakeKeys', () => { { certificate: { __typename: Cardano.CertificateType.StakeKeyDeregistration, - stakeKeyHash: Cardano.Ed25519KeyHash('3b62970858d61cf667701c1f34abef41659516b191d7d374e8b0857b') + stakeKeyHash: Crypto.Ed25519KeyHashHex('3b62970858d61cf667701c1f34abef41659516b191d7d374e8b0857b') }, pointer: {} as CertificatePointer }, { certificate: { __typename: Cardano.CertificateType.StakeKeyRegistration, - stakeKeyHash: Cardano.Ed25519KeyHash('3b62970858d61cf667701c1f34abef41659516b191d7d374e8b0857b') + stakeKeyHash: Crypto.Ed25519KeyHashHex('3b62970858d61cf667701c1f34abef41659516b191d7d374e8b0857b') }, pointer: {} as CertificatePointer } diff --git a/packages/projection/test/projectIntoSink.test.ts b/packages/projection/test/projectIntoSink.test.ts index ce3977e9017..b25fc0934d5 100644 --- a/packages/projection/test/projectIntoSink.test.ts +++ b/packages/projection/test/projectIntoSink.test.ts @@ -1,3 +1,4 @@ +import * as Crypto from '@cardano-sdk/crypto'; import { Cardano, ChainSyncEventType, ChainSyncRollForward } from '@cardano-sdk/core'; import { InvalidIntersectionError, projectIntoSink, projections, sinks } from '../src'; import { StubChainSyncData, dataWithPoolRetirement, dataWithStakeKeyDeregistration } from './events'; @@ -42,7 +43,7 @@ describe('projectIntoSink', () => { it('projects stakeKeys', async () => { await projectAll(dataWithStakeKeyDeregistration, inMemorySinks); expect(store.stakeKeys).toEqual( - new Set([Cardano.Ed25519KeyHash('3b62970858d61cf667701c1f34abef41659516b191d7d374e8b0857b')]) + new Set([Crypto.Ed25519KeyHashHex('3b62970858d61cf667701c1f34abef41659516b191d7d374e8b0857b')]) ); }); }); @@ -66,7 +67,7 @@ describe('projectIntoSink', () => { }); it('resuming from a fork rolls back and continues from intersection', async () => { - const rolledBackKey = Cardano.Ed25519KeyHash('3b62970858d61cf667701c1f34abef41659516b191d7d374e8b0857c'); + const rolledBackKey = Crypto.Ed25519KeyHashHex('3b62970858d61cf667701c1f34abef41659516b191d7d374e8b0857c'); store.stakeKeys.add(rolledBackKey); await lastValueFrom( concat( diff --git a/packages/projection/test/sinks/inMemory/stakeKeys.test.ts b/packages/projection/test/sinks/inMemory/stakeKeys.test.ts index a1cdc04f411..64340a83d9f 100644 --- a/packages/projection/test/sinks/inMemory/stakeKeys.test.ts +++ b/packages/projection/test/sinks/inMemory/stakeKeys.test.ts @@ -1,4 +1,5 @@ -import { Cardano, ChainSyncEventType } from '@cardano-sdk/core'; +import * as Crypto from '@cardano-sdk/crypto'; +import { ChainSyncEventType } from '@cardano-sdk/core'; import { InMemoryStore } from '../../../src/sinks'; import { defaultIfEmpty, firstValueFrom } from 'rxjs'; import { stakeKeys } from '../../../src/sinks/inMemory/stakeKeys'; @@ -11,8 +12,8 @@ describe('sinks/inMemory/stakeKeys', () => { }; const sink = async ( eventType: ChainSyncEventType, - register: Cardano.Ed25519KeyHash[], - deregister: Cardano.Ed25519KeyHash[] + register: Crypto.Ed25519KeyHashHex[], + deregister: Crypto.Ed25519KeyHashHex[] ) => { await firstValueFrom( stakeKeys @@ -27,31 +28,31 @@ describe('sinks/inMemory/stakeKeys', () => { }; await sink( ChainSyncEventType.RollForward, - [Cardano.Ed25519KeyHash('3b62970858d61cf667701c1f34abef41659516b191d7d374e8b0857b')], + [Crypto.Ed25519KeyHashHex('3b62970858d61cf667701c1f34abef41659516b191d7d374e8b0857b')], [] ); await sink( ChainSyncEventType.RollForward, - [Cardano.Ed25519KeyHash('3b62970858d61cf667701c1f34abef41659516b191d7d374e8b0857c')], + [Crypto.Ed25519KeyHashHex('3b62970858d61cf667701c1f34abef41659516b191d7d374e8b0857c')], [] ); expect(store.stakeKeys.size).toBe(2); await sink( ChainSyncEventType.RollForward, [], - [Cardano.Ed25519KeyHash('3b62970858d61cf667701c1f34abef41659516b191d7d374e8b0857c')] + [Crypto.Ed25519KeyHashHex('3b62970858d61cf667701c1f34abef41659516b191d7d374e8b0857c')] ); expect(store.stakeKeys.size).toBe(1); await sink( ChainSyncEventType.RollBackward, - [Cardano.Ed25519KeyHash('3b62970858d61cf667701c1f34abef41659516b191d7d374e8b0857b')], + [Crypto.Ed25519KeyHashHex('3b62970858d61cf667701c1f34abef41659516b191d7d374e8b0857b')], [] ); expect(store.stakeKeys.size).toBe(0); await sink( ChainSyncEventType.RollBackward, [], - [Cardano.Ed25519KeyHash('3b62970858d61cf667701c1f34abef41659516b191d7d374e8b0857b')] + [Crypto.Ed25519KeyHashHex('3b62970858d61cf667701c1f34abef41659516b191d7d374e8b0857b')] ); expect(store.stakeKeys.size).toBe(1); }); diff --git a/packages/util/src/primitives.ts b/packages/util/src/primitives.ts index 91c1c08c2cb..52883fc3956 100644 --- a/packages/util/src/primitives.ts +++ b/packages/util/src/primitives.ts @@ -116,26 +116,3 @@ export const castHexBlob = (target: HexBlob, expectedLength?: number) => { assertLength(expectedLength, target.toString()); return target as unknown as T; }; - -/** - * 32 byte hash as hex string - */ -export type Hash32ByteBase16 = OpaqueString<'Hash32ByteBase16'>; - -/** - * @param {string} value 32 byte hash as hex string - * @throws InvalidStringError - */ -export const Hash32ByteBase16 = (value: string): Hash32ByteBase16 => typedHex(value, 64); -Hash32ByteBase16.fromHexBlob = (value: HexBlob) => castHexBlob(value, 64); - -/** - * 28 byte hash as hex string - */ -export type Hash28ByteBase16 = OpaqueString<'Hash28ByteBase16'>; - -/** - * @param {string} value 28 byte hash as hex string - * @throws InvalidStringError - */ -export const Hash28ByteBase16 = (value: string): Hash28ByteBase16 => typedHex(value, 56); diff --git a/packages/util/test/primitives.test.ts b/packages/util/test/primitives.test.ts index 389d011860c..e812d8cd503 100644 --- a/packages/util/test/primitives.test.ts +++ b/packages/util/test/primitives.test.ts @@ -1,15 +1,6 @@ /* eslint-disable max-len */ /* eslint-disable sonarjs/no-duplicate-string */ -import { - Base64Blob, - Hash28ByteBase16, - Hash32ByteBase16, - HexBlob, - InvalidStringError, - castHexBlob, - typedBech32, - typedHex -} from '../src'; +import { Base64Blob, HexBlob, InvalidStringError, castHexBlob, typedBech32, typedHex } from '../src'; describe('Cardano.util/primitives', () => { describe('typedBech32', () => { @@ -145,49 +136,4 @@ describe('Cardano.util/primitives', () => { expect(() => castHexBlob(HexBlob('ABCDEF'), 5)).toThrowError(InvalidStringError); }); }); - - describe('Hash32ByteBase16', () => { - it('expects a hex string with length of 64', () => { - expect(() => Hash32ByteBase16('3e33018e8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d')).not.toThrow(); - expect(() => - Hash32ByteBase16.fromHexBlob(HexBlob('3e33018e8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d')) - ).not.toThrow(); - }); - - it('throws with non-hex string', () => { - expect(() => Hash32ByteBase16('ge33018e8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d')).toThrowError( - InvalidStringError - ); - expect(() => - Hash32ByteBase16.fromHexBlob(HexBlob('ge33018e8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d')) - ).toThrowError(InvalidStringError); - }); - - it('throws with hex string of different length', () => { - expect(() => Hash32ByteBase16('e33018e8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d')).toThrowError( - InvalidStringError - ); - expect(() => - Hash32ByteBase16.fromHexBlob(HexBlob('e33018e8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d')) - ).toThrowError(InvalidStringError); - }); - }); - - describe('Hash28ByteBase16', () => { - it('expects a hex string with length of 64', () => { - expect(() => Hash28ByteBase16('8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d')).not.toThrow(); - }); - - it('throws with non-hex string', () => { - expect(() => Hash28ByteBase16('g293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d')).toThrowError( - InvalidStringError - ); - }); - - it('throws with hex string of different length', () => { - expect(() => Hash28ByteBase16('293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d')).toThrowError( - InvalidStringError - ); - }); - }); }); diff --git a/packages/wallet/package.json b/packages/wallet/package.json index 82e5bc763f7..fd949be844f 100644 --- a/packages/wallet/package.json +++ b/packages/wallet/package.json @@ -76,6 +76,7 @@ }, "dependencies": { "@cardano-sdk/core": "^0.7.0", + "@cardano-sdk/crypto": "^0.1.0", "@cardano-sdk/dapp-connector": "^0.6.1", "@cardano-sdk/input-selection": "^0.7.0", "@cardano-sdk/key-management": "^0.3.0", diff --git a/packages/wallet/src/Transaction/createTransactionInternals.ts b/packages/wallet/src/Transaction/createTransactionInternals.ts index 1574b179097..1679dfb679e 100644 --- a/packages/wallet/src/Transaction/createTransactionInternals.ts +++ b/packages/wallet/src/Transaction/createTransactionInternals.ts @@ -1,6 +1,7 @@ +import * as Crypto from '@cardano-sdk/crypto'; import { CML, Cardano, coreToCml, util } from '@cardano-sdk/core'; -import { Hash32ByteBase16, usingAutoFree } from '@cardano-sdk/util'; import { SelectionResult } from '@cardano-sdk/input-selection'; +import { usingAutoFree } from '@cardano-sdk/util'; export type CreateTxInternalsProps = { changeAddress: Cardano.Address; @@ -11,8 +12,8 @@ export type CreateTxInternalsProps = { auxiliaryData?: Cardano.AuxiliaryData; collaterals?: Set; mint?: Cardano.TokenMap; - scriptIntegrityHash?: Hash32ByteBase16; - requiredExtraSignatures?: Cardano.Ed25519KeyHash[]; + scriptIntegrityHash?: Crypto.Hash32ByteBase16; + requiredExtraSignatures?: Crypto.Ed25519KeyHashHex[]; }; export const createTransactionInternals = async ({ diff --git a/packages/wallet/src/TxBuilder/OutputBuilder.ts b/packages/wallet/src/TxBuilder/OutputBuilder.ts index a05af54f2f4..7730b455701 100644 --- a/packages/wallet/src/TxBuilder/OutputBuilder.ts +++ b/packages/wallet/src/TxBuilder/OutputBuilder.ts @@ -1,6 +1,6 @@ import { Cardano } from '@cardano-sdk/core'; -import { Hash32ByteBase16 } from '@cardano-sdk/util'; +import { Hash32ByteBase16 } from '@cardano-sdk/crypto'; import { MaybeValidTxOut, OutputBuilder, diff --git a/packages/wallet/src/TxBuilder/buildTx.ts b/packages/wallet/src/TxBuilder/buildTx.ts index 5f422680330..1dee380a3de 100644 --- a/packages/wallet/src/TxBuilder/buildTx.ts +++ b/packages/wallet/src/TxBuilder/buildTx.ts @@ -1,4 +1,5 @@ /* eslint-disable max-len */ +import * as Crypto from '@cardano-sdk/crypto'; import { Cardano } from '@cardano-sdk/core'; import { FinalizeTxProps, InitializeTxProps, InitializeTxResult, ObservableWallet } from '../types'; import { @@ -219,7 +220,7 @@ export class ObservableWalletTxBuilder implements TxBuilder { this.partialTxBody = { ...this.partialTxBody, certificates: [] }; for (const rewardAccount of rewardAccounts) { - const stakeKeyHash = Cardano.Ed25519KeyHash.fromRewardAccount(rewardAccount.address); + const stakeKeyHash = Cardano.RewardAccount.toHash(rewardAccount.address); if (this.#delegateConfig.type === 'deregister') { // Deregister scenario if (rewardAccount.keyStatus === StakeKeyStatus.Unregistered) { @@ -258,7 +259,7 @@ export class ObservableWalletTxBuilder implements TxBuilder { static #createDelegationCert( poolId: Cardano.PoolId, - stakeKeyHash: Cardano.Ed25519KeyHash + stakeKeyHash: Crypto.Ed25519KeyHashHex ): Cardano.StakeDelegationCertificate { return { __typename: Cardano.CertificateType.StakeDelegation, diff --git a/packages/wallet/src/TxBuilder/types.ts b/packages/wallet/src/TxBuilder/types.ts index 2ce5a9512f4..7d7eb770c43 100644 --- a/packages/wallet/src/TxBuilder/types.ts +++ b/packages/wallet/src/TxBuilder/types.ts @@ -4,7 +4,7 @@ import { CustomError } from 'ts-custom-error'; import { InputSelectionError, SelectionSkeleton } from '@cardano-sdk/input-selection'; -import { Hash32ByteBase16 } from '@cardano-sdk/util'; +import { Hash32ByteBase16 } from '@cardano-sdk/crypto'; import { OutputValidation } from '../types'; import { SignTransactionOptions, TransactionSigner } from '@cardano-sdk/key-management'; diff --git a/packages/wallet/src/services/DelegationTracker/RewardAccounts.ts b/packages/wallet/src/services/DelegationTracker/RewardAccounts.ts index 4184092a9bb..847bf2d0f8e 100644 --- a/packages/wallet/src/services/DelegationTracker/RewardAccounts.ts +++ b/packages/wallet/src/services/DelegationTracker/RewardAccounts.ts @@ -176,7 +176,7 @@ const accountCertificateTransactions = ( transactions$: Observable, rewardAccount: Cardano.RewardAccount ) => { - const stakeKeyHash = Cardano.Ed25519KeyHash.fromRewardAccount(rewardAccount); + const stakeKeyHash = Cardano.RewardAccount.toHash(rewardAccount); return transactions$.pipe( map((transactions) => transactions diff --git a/packages/wallet/src/services/DelegationTracker/transactionCertificates.ts b/packages/wallet/src/services/DelegationTracker/transactionCertificates.ts index 94b8b78a248..72c565d91e7 100644 --- a/packages/wallet/src/services/DelegationTracker/transactionCertificates.ts +++ b/packages/wallet/src/services/DelegationTracker/transactionCertificates.ts @@ -22,7 +22,7 @@ export const isLastStakeKeyCertOfType = ( certType: Cardano.CertificateType.StakeKeyRegistration | Cardano.CertificateType.StakeKeyDeregistration, rewardAccount?: Cardano.RewardAccount ) => { - const stakeKeyHash = rewardAccount ? Cardano.Ed25519KeyHash.fromRewardAccount(rewardAccount) : null; + const stakeKeyHash = rewardAccount ? Cardano.RewardAccount.toHash(rewardAccount) : null; const lastRegOrDereg = last( transactionsCertificates .map((certificates) => { diff --git a/packages/wallet/src/setupWallet.ts b/packages/wallet/src/setupWallet.ts index 60962759006..a292a731849 100644 --- a/packages/wallet/src/setupWallet.ts +++ b/packages/wallet/src/setupWallet.ts @@ -1,3 +1,4 @@ +import * as Crypto from '@cardano-sdk/crypto'; import { AsyncKeyAgent, KeyAgentDependencies } from '@cardano-sdk/key-management'; import { Logger } from 'ts-log'; import { ObservableWallet } from './types'; @@ -7,6 +8,7 @@ export interface SetupWalletProps { createKeyAgent: (dependencies: KeyAgentDependencies) => Promise; createWallet: (keyAgent: TKeyAgent) => Promise; logger: Logger; + bip32Ed25519: Crypto.Bip32Ed25519; } /** @@ -19,10 +21,11 @@ export interface SetupWalletProps { export const setupWallet = async ({ createKeyAgent, createWallet, - logger + logger, + bip32Ed25519 }: SetupWalletProps) => { const walletUtil = createLazyWalletUtil(); - const keyAgent = await createKeyAgent({ inputResolver: walletUtil, logger }); + const keyAgent = await createKeyAgent({ bip32Ed25519, inputResolver: walletUtil, logger }); const wallet = await createWallet(keyAgent); walletUtil.initialize(wallet); return { keyAgent, wallet, walletUtil: walletUtil as WalletUtil }; diff --git a/packages/wallet/src/types.ts b/packages/wallet/src/types.ts index 5447c51358f..831ad4f9127 100644 --- a/packages/wallet/src/types.ts +++ b/packages/wallet/src/types.ts @@ -1,10 +1,11 @@ +import * as Crypto from '@cardano-sdk/crypto'; import { Asset, Cardano, EpochInfo, EraSummary, NetworkInfoProvider } from '@cardano-sdk/core'; import { BalanceTracker, DelegationTracker, TransactionalObservables, TransactionsTracker } from './services'; import { Cip30DataSignature } from '@cardano-sdk/dapp-connector'; import { GroupedAddress, SignTransactionOptions, TransactionSigner, cip8 } from '@cardano-sdk/key-management'; -import { Hash32ByteBase16, Shutdown } from '@cardano-sdk/util'; import { Observable } from 'rxjs'; import { SelectionSkeleton } from '@cardano-sdk/input-selection'; +import { Shutdown } from '@cardano-sdk/util'; export type InitializeTxProps = { outputs?: Set; @@ -15,8 +16,8 @@ export type InitializeTxProps = { }; collaterals?: Set; mint?: Cardano.TokenMap; - scriptIntegrityHash?: Hash32ByteBase16; - requiredExtraSignatures?: Cardano.Ed25519KeyHash[]; + scriptIntegrityHash?: Crypto.Hash32ByteBase16; + requiredExtraSignatures?: Crypto.Ed25519KeyHashHex[]; extraSigners?: TransactionSigner[]; signingOptions?: SignTransactionOptions; scripts?: Cardano.Script[]; diff --git a/packages/wallet/test/SingleAddressWallet/load.test.ts b/packages/wallet/test/SingleAddressWallet/load.test.ts index 6bb0a736b96..abaa477935c 100644 --- a/packages/wallet/test/SingleAddressWallet/load.test.ts +++ b/packages/wallet/test/SingleAddressWallet/load.test.ts @@ -1,5 +1,6 @@ /* eslint-disable max-statements */ /* eslint-disable @typescript-eslint/no-explicit-any */ +import * as Crypto from '@cardano-sdk/crypto'; import * as mocks from '../mocks'; import { AddressType, GroupedAddress } from '@cardano-sdk/key-management'; import { @@ -10,6 +11,7 @@ import { somePartialStakePools } from '@cardano-sdk/util-dev'; import { + CML, Cardano, ChainHistoryProvider, NetworkInfoProvider, @@ -49,6 +51,7 @@ interface Providers { const createWallet = async (stores: WalletStores, providers: Providers, pollingConfig?: PollingConfig) => { const { wallet } = await setupWallet({ + bip32Ed25519: new Crypto.CmlBip32Ed25519(CML), createKeyAgent: async (dependencies) => { const groupedAddress: GroupedAddress = { accountIndex: 0, diff --git a/packages/wallet/test/SingleAddressWallet/methods.test.ts b/packages/wallet/test/SingleAddressWallet/methods.test.ts index cfad94ba262..36a0bdd7e7c 100644 --- a/packages/wallet/test/SingleAddressWallet/methods.test.ts +++ b/packages/wallet/test/SingleAddressWallet/methods.test.ts @@ -1,9 +1,10 @@ /* eslint-disable max-len */ +import * as Crypto from '@cardano-sdk/crypto'; import * as mocks from '../mocks'; import { AddressType, GroupedAddress } from '@cardano-sdk/key-management'; import { AssetId, createStubStakePoolProvider } from '@cardano-sdk/util-dev'; -import { Cardano, CardanoNodeErrors, ProviderError, ProviderFailure } from '@cardano-sdk/core'; -import { Hash32ByteBase16, HexBlob } from '@cardano-sdk/util'; +import { CML, Cardano, CardanoNodeErrors, ProviderError, ProviderFailure } from '@cardano-sdk/core'; +import { HexBlob } from '@cardano-sdk/util'; import { InitializeTxProps, SingleAddressWallet, setupWallet } from '../../src'; import { firstValueFrom, skip } from 'rxjs'; import { getPassword, testAsyncKeyAgent } from '../../../key-management/test/mocks'; @@ -54,6 +55,7 @@ describe('SingleAddressWallet methods', () => { type: AddressType.External }; ({ wallet } = await setupWallet({ + bip32Ed25519: new Crypto.CmlBip32Ed25519(CML), createKeyAgent: async (dependencies) => { const asyncKeyAgent = await testAsyncKeyAgent([groupedAddress], dependencies); asyncKeyAgent.deriveAddress = jest.fn().mockResolvedValue(groupedAddress); @@ -159,8 +161,8 @@ describe('SingleAddressWallet methods', () => { [AssetId.TSLA, 20n] ]), outputs: new Set(outputs), - requiredExtraSignatures: [Cardano.Ed25519KeyHash('6199186adb51974690d7247d2646097d2c62763b767b528816fb7ed5')], - scriptIntegrityHash: Hash32ByteBase16('3e33018e8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d') + requiredExtraSignatures: [Crypto.Ed25519KeyHashHex('6199186adb51974690d7247d2646097d2c62763b767b528816fb7ed5')], + scriptIntegrityHash: Crypto.Hash32ByteBase16('3e33018e8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d') } as InitializeTxProps; it('initializeTx', async () => { diff --git a/packages/wallet/test/SingleAddressWallet/rollback.test.ts b/packages/wallet/test/SingleAddressWallet/rollback.test.ts index 47f5d39a0cc..5f73de50fca 100644 --- a/packages/wallet/test/SingleAddressWallet/rollback.test.ts +++ b/packages/wallet/test/SingleAddressWallet/rollback.test.ts @@ -1,4 +1,8 @@ +import * as Crypto from '@cardano-sdk/crypto'; +import * as mocks from '../mocks'; +import { AddressType, GroupedAddress } from '@cardano-sdk/key-management'; import { + CML, Cardano, ChainHistoryProvider, NetworkInfoProvider, @@ -6,14 +10,11 @@ import { TxSubmitProvider, UtxoProvider } from '@cardano-sdk/core'; +import { ConnectionStatusTracker, PollingConfig, SingleAddressWallet, setupWallet } from '../../src'; +import { WalletStores, createInMemoryWalletStores } from '../../src/persistence'; import { createStubStakePoolProvider } from '@cardano-sdk/util-dev'; import { filter, firstValueFrom } from 'rxjs'; import { dummyLogger as logger } from 'ts-log'; - -import * as mocks from '../mocks'; -import { AddressType, GroupedAddress } from '@cardano-sdk/key-management'; -import { ConnectionStatusTracker, PollingConfig, SingleAddressWallet, setupWallet } from '../../src'; -import { WalletStores, createInMemoryWalletStores } from '../../src/persistence'; import { testAsyncKeyAgent } from '../../../key-management/test/mocks'; import { waitForWalletStateSettle } from '../util'; @@ -32,6 +33,7 @@ interface Providers { const createWallet = async (stores: WalletStores, providers: Providers, pollingConfig?: PollingConfig) => { const { wallet } = await setupWallet({ + bip32Ed25519: new Crypto.CmlBip32Ed25519(CML), createKeyAgent: async (dependencies) => { const groupedAddress: GroupedAddress = { accountIndex: 0, @@ -111,7 +113,7 @@ const tx: Cardano.Tx = { body: txBody, id: Cardano.TransactionId('de9d33f66cffff721673219b19470aec81d96bc9253182369e41eec58389a448'), witness: { - signatures: new Map([[Cardano.Ed25519PublicKey(vkey), Cardano.Ed25519Signature(signature)]]) + signatures: new Map([[Crypto.Ed25519PublicKeyHex(vkey), Crypto.Ed25519SignatureHex(signature)]]) } }; diff --git a/packages/wallet/test/SingleAddressWallet/shutdown.test.ts b/packages/wallet/test/SingleAddressWallet/shutdown.test.ts index 4a7a9e66b8d..91d122af0f9 100644 --- a/packages/wallet/test/SingleAddressWallet/shutdown.test.ts +++ b/packages/wallet/test/SingleAddressWallet/shutdown.test.ts @@ -1,9 +1,11 @@ /* eslint-disable max-statements */ /* eslint-disable @typescript-eslint/no-explicit-any */ +import * as Crypto from '@cardano-sdk/crypto'; import * as mocks from '../mocks'; import { AddressType, GroupedAddress } from '@cardano-sdk/key-management'; import { AssetId, createStubStakePoolProvider, somePartialStakePools } from '@cardano-sdk/util-dev'; import { + CML, Cardano, ChainHistoryProvider, NetworkInfoProvider, @@ -45,6 +47,7 @@ const createWallet = async ( pollingConfig?: PollingConfig ) => { const { wallet } = await setupWallet({ + bip32Ed25519: new Crypto.CmlBip32Ed25519(CML), createKeyAgent: async (dependencies) => { const groupedAddress: GroupedAddress = { accountIndex: 0, diff --git a/packages/wallet/test/Transaction/createTransactionInternals.test.ts b/packages/wallet/test/Transaction/createTransactionInternals.test.ts index 827a13a101f..50761ccc1c6 100644 --- a/packages/wallet/test/Transaction/createTransactionInternals.test.ts +++ b/packages/wallet/test/Transaction/createTransactionInternals.test.ts @@ -1,7 +1,7 @@ +import * as Crypto from '@cardano-sdk/crypto'; import { AssetId } from '@cardano-sdk/util-dev'; import { Cardano, NetworkInfoProvider } from '@cardano-sdk/core'; import { CreateTxInternalsProps, createTransactionInternals } from '../../src/Transaction'; -import { Hash32ByteBase16 } from '@cardano-sdk/util'; import { SelectionConstraints } from '../../../input-selection/test/util'; import { SelectionSkeleton, roundRobinRandomImprove } from '@cardano-sdk/input-selection'; import { mockNetworkInfoProvider, utxo } from '../mocks'; @@ -61,15 +61,15 @@ describe('Transaction.createTransactionInternals', () => { [AssetId.PXL, 5n], [AssetId.TSLA, 20n] ]), - requiredExtraSignatures: [Cardano.Ed25519KeyHash('6199186adb51974690d7247d2646097d2c62763b767b528816fb7ed5')], - scriptIntegrityHash: Hash32ByteBase16('3e33018e8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d') + requiredExtraSignatures: [Crypto.Ed25519KeyHashHex('6199186adb51974690d7247d2646097d2c62763b767b528816fb7ed5')], + scriptIntegrityHash: Crypto.Hash32ByteBase16('3e33018e8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d') }; const txInternals = await createSimpleTransactionInternals(() => props); expect(txInternals.body.outputs).toHaveLength(2); expect(txInternals.body.collaterals).toEqual([utxo[2][0]]); expect(txInternals.body.mint).toEqual(props.mint); - expect(txInternals.body.requiredExtraSignatures).toEqual(props.requiredExtraSignatures); - expect(txInternals.body.scriptIntegrityHash).toEqual(props.scriptIntegrityHash); + expect(txInternals.body.requiredExtraSignatures).toEqual(props.requiredExtraSignatures); + expect(txInternals.body.scriptIntegrityHash).toEqual(props.scriptIntegrityHash); expect(typeof txInternals.body.fee).toBe('bigint'); expect(typeof txInternals.body.inputs[0].txId).toBe('string'); expect(typeof txInternals.hash).toBe('string'); diff --git a/packages/wallet/test/hardware/LedgerKeyAgent.integration.test.ts b/packages/wallet/test/hardware/LedgerKeyAgent.integration.test.ts index 0c832a70336..82ce94f1125 100644 --- a/packages/wallet/test/hardware/LedgerKeyAgent.integration.test.ts +++ b/packages/wallet/test/hardware/LedgerKeyAgent.integration.test.ts @@ -1,4 +1,5 @@ -import { Cardano } from '@cardano-sdk/core'; +import * as Crypto from '@cardano-sdk/crypto'; +import { CML, Cardano } from '@cardano-sdk/core'; import { CommunicationType, KeyAgent, LedgerKeyAgent, restoreKeyAgent, util } from '@cardano-sdk/key-management'; import { ObservableWallet, SingleAddressWallet, setupWallet } from '../../src'; import { createStubStakePoolProvider } from '@cardano-sdk/util-dev'; @@ -43,6 +44,7 @@ const getAddress = async (wallet: ObservableWallet) => (await firstValueFrom(wal describe('LedgerKeyAgent+SingleAddressWallet', () => { test('creating and restoring LedgerKeyAgent wallet', async () => { const { wallet: freshWallet, keyAgent: freshKeyAgent } = await setupWallet({ + bip32Ed25519: new Crypto.CmlBip32Ed25519(CML), createKeyAgent: (dependencies) => LedgerKeyAgent.createWithDevice( { @@ -55,6 +57,7 @@ describe('LedgerKeyAgent+SingleAddressWallet', () => { logger }); const { wallet: restoredWallet } = await setupWallet({ + bip32Ed25519: new Crypto.CmlBip32Ed25519(CML), createKeyAgent: (dependencies) => restoreKeyAgent(freshKeyAgent.serializableData, dependencies), createWallet, logger diff --git a/packages/wallet/test/hardware/LedgerKeyAgent.test.ts b/packages/wallet/test/hardware/LedgerKeyAgent.test.ts index c3b0a0032be..a22d82a1758 100644 --- a/packages/wallet/test/hardware/LedgerKeyAgent.test.ts +++ b/packages/wallet/test/hardware/LedgerKeyAgent.test.ts @@ -1,4 +1,5 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ +import * as Crypto from '@cardano-sdk/crypto'; import * as mocks from '../mocks'; import { AddressType, @@ -10,7 +11,7 @@ import { util } from '@cardano-sdk/key-management'; import { AssetId, createStubStakePoolProvider } from '@cardano-sdk/util-dev'; -import { Cardano } from '@cardano-sdk/core'; +import { CML, Cardano } from '@cardano-sdk/core'; import { SingleAddressWallet, setupWallet } from '../../src'; import { dummyLogger as logger } from 'ts-log'; import { mockKeyAgentDependencies } from '@cardano-sdk/key-management/test/mocks'; @@ -25,6 +26,7 @@ describe('LedgerKeyAgent', () => { beforeAll(async () => { txSubmitProvider = mocks.mockTxSubmitProvider(); ({ keyAgent, wallet } = await setupWallet({ + bip32Ed25519: new Crypto.CmlBip32Ed25519(CML), createKeyAgent: async (dependencies) => { const ledgerKeyAgent = await LedgerKeyAgent.createWithDevice( { diff --git a/packages/wallet/test/hardware/TrezorKeyAgent.integration.test.ts b/packages/wallet/test/hardware/TrezorKeyAgent.integration.test.ts index f2180b6a7d0..6dfae8868f6 100644 --- a/packages/wallet/test/hardware/TrezorKeyAgent.integration.test.ts +++ b/packages/wallet/test/hardware/TrezorKeyAgent.integration.test.ts @@ -1,4 +1,5 @@ -import { Cardano } from '@cardano-sdk/core'; +import * as Crypto from '@cardano-sdk/crypto'; +import { CML, Cardano } from '@cardano-sdk/core'; import { CommunicationType, KeyAgent, TrezorKeyAgent, restoreKeyAgent, util } from '@cardano-sdk/key-management'; import { ObservableWallet, SingleAddressWallet, setupWallet } from '../../src'; import { createStubStakePoolProvider } from '@cardano-sdk/util-dev'; @@ -43,6 +44,7 @@ const getAddress = async (wallet: ObservableWallet) => (await firstValueFrom(wal describe('TrezorKeyAgent+SingleAddressWallet', () => { test('creating and restoring TrezorKeyAgent wallet', async () => { const { wallet: freshWallet, keyAgent: freshKeyAgent } = await setupWallet({ + bip32Ed25519: new Crypto.CmlBip32Ed25519(CML), createKeyAgent: (dependencies) => TrezorKeyAgent.createWithDevice( { @@ -61,6 +63,7 @@ describe('TrezorKeyAgent+SingleAddressWallet', () => { logger }); const { wallet: restoredWallet } = await setupWallet({ + bip32Ed25519: new Crypto.CmlBip32Ed25519(CML), createKeyAgent: (dependencies) => restoreKeyAgent(freshKeyAgent.serializableData, dependencies), createWallet, logger diff --git a/packages/wallet/test/hardware/TrezorKeyAgent.test.ts b/packages/wallet/test/hardware/TrezorKeyAgent.test.ts index 4fcab81e715..d409d72dd95 100644 --- a/packages/wallet/test/hardware/TrezorKeyAgent.test.ts +++ b/packages/wallet/test/hardware/TrezorKeyAgent.test.ts @@ -1,3 +1,4 @@ +import * as Crypto from '@cardano-sdk/crypto'; import * as mocks from '../mocks'; import { AddressType, @@ -8,7 +9,7 @@ import { util } from '@cardano-sdk/key-management'; import { AssetId, createStubStakePoolProvider } from '@cardano-sdk/util-dev'; -import { Cardano } from '@cardano-sdk/core'; +import { CML, Cardano } from '@cardano-sdk/core'; import { SingleAddressWallet, setupWallet } from '../../src'; import { dummyLogger as logger } from 'ts-log'; import { mockKeyAgentDependencies } from '../../../key-management/test/mocks'; @@ -28,6 +29,8 @@ describe('TrezorKeyAgent', () => { beforeAll(async () => { txSubmitProvider = mocks.mockTxSubmitProvider(); ({ keyAgent, wallet } = await setupWallet({ + bip32Ed25519: new Crypto.CmlBip32Ed25519(CML), + createKeyAgent: async (dependencies) => { const trezorKeyAgent = await TrezorKeyAgent.createWithDevice( { @@ -49,7 +52,6 @@ describe('TrezorKeyAgent', () => { trezorKeyAgent.knownAddresses.push(groupedAddress); return trezorKeyAgent; }, - createWallet: async (trezorKeyAgent) => { const assetProvider = mocks.mockAssetProvider(); const stakePoolProvider = createStubStakePoolProvider(); diff --git a/packages/wallet/test/integration/buildTx.test.ts b/packages/wallet/test/integration/buildTx.test.ts index 0c7b9b54153..4f01bca6831 100644 --- a/packages/wallet/test/integration/buildTx.test.ts +++ b/packages/wallet/test/integration/buildTx.test.ts @@ -1,11 +1,12 @@ /* eslint-disable func-style */ /* eslint-disable jsdoc/require-jsdoc */ +import * as Crypto from '@cardano-sdk/crypto'; import { AssetId, logger, somePartialStakePools } from '@cardano-sdk/util-dev'; import { Cardano, CardanoNodeErrors } from '@cardano-sdk/core'; + import { of } from 'rxjs'; import * as mocks from '../mocks'; -import { Hash32ByteBase16 } from '@cardano-sdk/util'; import { IncompatibleWalletError, ObservableWallet, @@ -115,8 +116,8 @@ describe('buildTx', () => { describe('setExtraSigners', () => { let signers: TransactionSigner[]; - const pubKey = Cardano.Ed25519PublicKey('6199186adb51974690d7247d2646097d2c62763b767b528816fb7ed3f9f55d39'); - const signature = Cardano.Ed25519Signature( + const pubKey = Crypto.Ed25519PublicKeyHex('6199186adb51974690d7247d2646097d2c62763b767b528816fb7ed3f9f55d39'); + const signature = Crypto.Ed25519SignatureHex( // eslint-disable-next-line max-len '709f937c4ce152c81f8406c03279ff5a8556a12a8657e40a578eaaa6223d2e6a2fece39733429e3ec73a6c798561b5c2d47d82224d656b1d964cfe8b5fdffe09' ); @@ -191,7 +192,7 @@ describe('buildTx', () => { let assetQuantity: bigint; let assets: Cardano.TokenMap; let address: Cardano.Address; - let datumHash: Hash32ByteBase16; + let datumHash: Crypto.Hash32ByteBase16; let output1Coin: bigint; let output2Base: Cardano.TxOut; @@ -200,7 +201,7 @@ describe('buildTx', () => { assetQuantity = 100n; assets = new Map([[assetId, assetQuantity]]); address = Cardano.Address('addr_test1vr8nl4u0u6fmtfnawx2rxfz95dy7m46t6dhzdftp2uha87syeufdg'); - datumHash = Hash32ByteBase16('3e33018e8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d'); + datumHash = Crypto.Hash32ByteBase16('3e33018e8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d'); output1Coin = 10_000_000n; output2Base = mocks.utxo[0][1]; diff --git a/packages/wallet/test/integration/util.ts b/packages/wallet/test/integration/util.ts index a63ae31839e..449602e320b 100644 --- a/packages/wallet/test/integration/util.ts +++ b/packages/wallet/test/integration/util.ts @@ -1,3 +1,5 @@ +import * as Crypto from '@cardano-sdk/crypto'; +import { CML } from '@cardano-sdk/core'; import { SingleAddressWallet, setupWallet } from '../../src'; import { WalletStores } from '../../src/persistence'; import { createStubStakePoolProvider } from '@cardano-sdk/util-dev'; @@ -14,6 +16,7 @@ import { testAsyncKeyAgent } from '../../../key-management/test/mocks'; export const createWallet = async (stores?: WalletStores) => setupWallet({ + bip32Ed25519: new Crypto.CmlBip32Ed25519(CML), createKeyAgent: (dependencies) => testAsyncKeyAgent(undefined, dependencies), createWallet: async (keyAgent) => { const txSubmitProvider = mockTxSubmitProvider(); diff --git a/packages/wallet/test/integration/withdrawal.test.ts b/packages/wallet/test/integration/withdrawal.test.ts index b75149dd3d4..801db02743f 100644 --- a/packages/wallet/test/integration/withdrawal.test.ts +++ b/packages/wallet/test/integration/withdrawal.test.ts @@ -88,7 +88,7 @@ describe('integration/withdrawal', () => { certificates: [ { __typename: Cardano.CertificateType.StakeKeyDeregistration, - stakeKeyHash: Cardano.Ed25519KeyHash.fromRewardAccount(rewardAccount) + stakeKeyHash: Cardano.RewardAccount.toHash(rewardAccount) } ], outputs: new Set() // In a real transaction you would probably want to have some outputs diff --git a/packages/wallet/test/mocks/mockData.ts b/packages/wallet/test/mocks/mockData.ts index fcb87c99592..a204da6424a 100644 --- a/packages/wallet/test/mocks/mockData.ts +++ b/packages/wallet/test/mocks/mockData.ts @@ -2,7 +2,7 @@ import { Cardano, EpochRewards, Seconds } from '@cardano-sdk/core'; import { KeyRole } from '@cardano-sdk/key-management'; export const rewardAccount = Cardano.RewardAccount('stake_test1up7pvfq8zn4quy45r2g572290p9vf99mr9tn7r9xrgy2l2qdsf58d'); -export const stakeKeyHash = Cardano.Ed25519KeyHash.fromRewardAccount(rewardAccount); +export const stakeKeyHash = Cardano.RewardAccount.toHash(rewardAccount); export const stakeKeyDerivationPath = { index: 0, diff --git a/packages/wallet/test/mocks/mockRewardsProvider.ts b/packages/wallet/test/mocks/mockRewardsProvider.ts index e3fa0ef22e6..77248810d3f 100644 --- a/packages/wallet/test/mocks/mockRewardsProvider.ts +++ b/packages/wallet/test/mocks/mockRewardsProvider.ts @@ -1,5 +1,5 @@ import { Cardano, Paginated, StakePoolProvider } from '@cardano-sdk/core'; -import { Hash32ByteBase16 } from '@cardano-sdk/util'; +import { Hash32ByteBase16 } from '@cardano-sdk/crypto'; import { getRandomTxId } from './mockChainHistoryProvider'; import { rewardAccountBalance, rewardAccountBalance2, rewardsHistory, rewardsHistory2 } from './mockData'; import delay from 'delay'; diff --git a/packages/wallet/test/services/DelegationTracker/DelegationTracker.test.ts b/packages/wallet/test/services/DelegationTracker/DelegationTracker.test.ts index ec6cfd4aef8..e525251af49 100644 --- a/packages/wallet/test/services/DelegationTracker/DelegationTracker.test.ts +++ b/packages/wallet/test/services/DelegationTracker/DelegationTracker.test.ts @@ -42,7 +42,7 @@ describe('DelegationTracker', () => { createStubTxWithCertificates([ { __typename: Cardano.CertificateType.StakeKeyRegistration, - stakeKeyHash: Cardano.Ed25519KeyHash.fromRewardAccount(rewardAccount) + stakeKeyHash: Cardano.RewardAccount.toHash(rewardAccount) } ]), createStubTxWithCertificates([ @@ -51,14 +51,14 @@ describe('DelegationTracker', () => { } as Cardano.Certificate, { __typename: Cardano.CertificateType.StakeDelegation, - stakeKeyHash: Cardano.Ed25519KeyHash.fromRewardAccount(rewardAccount) + stakeKeyHash: Cardano.RewardAccount.toHash(rewardAccount) } as Cardano.Certificate ]), createStubTxWithCertificates(), createStubTxWithCertificates([ { __typename: Cardano.CertificateType.StakeKeyDeregistration, - stakeKeyHash: Cardano.Ed25519KeyHash.fromRewardAccount(rewardAccount) + stakeKeyHash: Cardano.RewardAccount.toHash(rewardAccount) } ]) ]; diff --git a/packages/wallet/test/services/DelegationTracker/RewardAccounts.test.ts b/packages/wallet/test/services/DelegationTracker/RewardAccounts.test.ts index c9f8ae391a6..bf7d58e305b 100644 --- a/packages/wallet/test/services/DelegationTracker/RewardAccounts.test.ts +++ b/packages/wallet/test/services/DelegationTracker/RewardAccounts.test.ts @@ -118,7 +118,7 @@ describe('RewardAccounts', () => { test('addressKeyStatuses ', () => { createTestScheduler().run(({ cold, expectObservable }) => { const rewardAccount = Cardano.RewardAccount('stake_test1uqfu74w3wh4gfzu8m6e7j987h4lq9r3t7ef5gaw497uu85qsqfy27'); - const stakeKeyHash = Cardano.Ed25519KeyHash.fromRewardAccount(rewardAccount); + const stakeKeyHash = Cardano.RewardAccount.toHash(rewardAccount); const transactions$ = cold('a-b-c', { a: [], b: [ diff --git a/packages/wallet/test/services/DelegationTracker/RewardsHistory.test.ts b/packages/wallet/test/services/DelegationTracker/RewardsHistory.test.ts index 326b287506c..707231cc469 100644 --- a/packages/wallet/test/services/DelegationTracker/RewardsHistory.test.ts +++ b/packages/wallet/test/services/DelegationTracker/RewardsHistory.test.ts @@ -59,7 +59,7 @@ describe('RewardsHistory', () => { epoch, tx: createStubTxWithCertificates( [{ __typename: Cardano.CertificateType.StakeDelegation } as Cardano.Certificate], - { stakeKeyHash: Cardano.Ed25519KeyHash.fromRewardAccount(rewardAccount) } + { stakeKeyHash: Cardano.RewardAccount.toHash(rewardAccount) } ) } ] @@ -106,7 +106,7 @@ describe('RewardsHistory', () => { epoch, tx: createStubTxWithCertificates( [{ __typename: Cardano.CertificateType.StakeDelegation } as Cardano.Certificate], - { stakeKeyHash: Cardano.Ed25519KeyHash.fromRewardAccount(rewardAccount) } + { stakeKeyHash: Cardano.RewardAccount.toHash(rewardAccount) } ) } ] diff --git a/packages/wallet/test/services/DelegationTracker/transactionCertificates.test.ts b/packages/wallet/test/services/DelegationTracker/transactionCertificates.test.ts index 37c34dad33f..e28d4d8c9f0 100644 --- a/packages/wallet/test/services/DelegationTracker/transactionCertificates.test.ts +++ b/packages/wallet/test/services/DelegationTracker/transactionCertificates.test.ts @@ -16,7 +16,7 @@ describe('transactionCertificates', () => { test('isLastStakeKeyCertOfType', () => { const rewardAccount = Cardano.RewardAccount('stake_test1up7pvfq8zn4quy45r2g572290p9vf99mr9tn7r9xrgy2l2qdsf58d'); - const stakeKeyHash = Cardano.Ed25519KeyHash.fromRewardAccount(rewardAccount); + const stakeKeyHash = Cardano.RewardAccount.toHash(rewardAccount); const certificates = [ [ { diff --git a/packages/wallet/test/setupWallet.test.ts b/packages/wallet/test/setupWallet.test.ts index 6e237d99406..010295e75dd 100644 --- a/packages/wallet/test/setupWallet.test.ts +++ b/packages/wallet/test/setupWallet.test.ts @@ -1,3 +1,5 @@ +import * as Crypto from '@cardano-sdk/crypto'; +import { CML } from '@cardano-sdk/core'; import { logger } from '@cardano-sdk/util-dev'; import { setupWallet } from '../src'; @@ -5,6 +7,8 @@ jest.mock('../src/services/WalletUtil'); const { createLazyWalletUtil } = jest.requireMock('../src/services/WalletUtil'); describe('setupWallet', () => { + const bip32Ed25519 = new Crypto.CmlBip32Ed25519(CML); + it('initializes WalletUtil with the wallet that is then used as InputResolver for KeyAgent', async () => { const initialize = jest.fn(); const walletUtil = { initialize }; @@ -17,13 +21,14 @@ describe('setupWallet', () => { const createWallet = jest.fn().mockResolvedValueOnce(wallet); expect( await setupWallet({ + bip32Ed25519, createKeyAgent, createWallet, logger }) ).toEqual({ keyAgent, wallet, walletUtil }); expect(initialize).toBeCalledWith(wallet); - expect(createKeyAgent).toBeCalledWith({ inputResolver: walletUtil, logger }); + expect(createKeyAgent).toBeCalledWith({ bip32Ed25519, inputResolver: walletUtil, logger }); expect(createWallet).toBeCalledWith(keyAgent); }); }); diff --git a/packages/web-extension/package.json b/packages/web-extension/package.json index 8c3e7628dd9..87a3f21640c 100644 --- a/packages/web-extension/package.json +++ b/packages/web-extension/package.json @@ -70,6 +70,7 @@ }, "dependencies": { "@cardano-sdk/core": "^0.7.0", + "@cardano-sdk/crypto": "^0.1.0", "@cardano-sdk/dapp-connector": "^0.6.1", "@cardano-sdk/key-management": "^0.3.0", "@cardano-sdk/util": "^0.7.0", diff --git a/packages/web-extension/src/keyAgent/util.ts b/packages/web-extension/src/keyAgent/util.ts index 90857f62cbe..98759e62029 100644 --- a/packages/web-extension/src/keyAgent/util.ts +++ b/packages/web-extension/src/keyAgent/util.ts @@ -6,6 +6,7 @@ export const keyAgentChannel = (walletName: string) => `${walletName}$-keyAgent` export const keyAgentProperties: RemoteApiProperties = { deriveAddress: RemoteApiPropertyType.MethodReturningPromise, derivePublicKey: RemoteApiPropertyType.MethodReturningPromise, + getBip32Ed25519: RemoteApiPropertyType.MethodReturningPromise, getChainId: RemoteApiPropertyType.MethodReturningPromise, getExtendedAccountPublicKey: RemoteApiPropertyType.MethodReturningPromise, knownAddresses$: RemoteApiPropertyType.HotObservable, diff --git a/packages/web-extension/test/walletManager/util.test.ts b/packages/web-extension/test/walletManager/util.test.ts index 7b99236c582..1356da3c8d2 100644 --- a/packages/web-extension/test/walletManager/util.test.ts +++ b/packages/web-extension/test/walletManager/util.test.ts @@ -1,9 +1,11 @@ +import * as Crypto from '@cardano-sdk/crypto'; import { AsyncKeyAgent } from '@cardano-sdk/key-management'; import { Cardano } from '@cardano-sdk/core'; + import { getWalletId } from '../../src'; describe('getWalletId', () => { - let pubKey: Cardano.Bip32PublicKey; + let pubKey: Crypto.Bip32PublicKeyHex; const chainId: Cardano.ChainId = { networkId: Cardano.NetworkId.Testnet, networkMagic: Cardano.NetworkMagics.Preview @@ -14,7 +16,7 @@ describe('getWalletId', () => { } as AsyncKeyAgent; beforeEach(() => { - pubKey = Cardano.Bip32PublicKey( + pubKey = Crypto.Bip32PublicKeyHex( // eslint-disable-next-line max-len '3e33018e8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d3e33018e8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d' ); @@ -36,7 +38,7 @@ describe('getWalletId', () => { it('create unique id for different public keys', async () => { const id1 = await getWalletId(mockKeyAgent); - pubKey = Cardano.Bip32PublicKey( + pubKey = Crypto.Bip32PublicKeyHex( // eslint-disable-next-line max-len '4e33018e8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d3e33018e8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d' ); diff --git a/packages/web-extension/test/walletManager/walletManagerUi.test.ts b/packages/web-extension/test/walletManager/walletManagerUi.test.ts index 20ba460f385..2d1da4f4307 100644 --- a/packages/web-extension/test/walletManager/walletManagerUi.test.ts +++ b/packages/web-extension/test/walletManager/walletManagerUi.test.ts @@ -3,6 +3,7 @@ import { AsyncKeyAgent } from '@cardano-sdk/key-management'; import { Cardano } from '@cardano-sdk/core'; import { logger } from '@cardano-sdk/util-dev'; +import { Bip32PublicKeyHex } from '@cardano-sdk/crypto'; import { WalletManagerUi, consumeRemoteApi, @@ -32,7 +33,7 @@ describe('WalletManagerUi', () => { const exposeApiMock = exposeApi as jest.Mock; const consumeRemoteApiMock = consumeRemoteApi as jest.Mock; - const pubKey = Cardano.Bip32PublicKey( + const pubKey = Bip32PublicKeyHex( // eslint-disable-next-line max-len '3e33018e8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d3e33018e8293d319ef5b3ac72366dd28006bd315b715f7e7cfcbd3004129b80d' ); diff --git a/yarn-project.nix b/yarn-project.nix index 0f9adcd6e18..f32de50bfb7 100644 --- a/yarn-project.nix +++ b/yarn-project.nix @@ -482,8 +482,8 @@ cacheEntries = { "@nodelib/fs.walk@npm:1.2.8" = { filename = "@nodelib-fs.walk-npm-1.2.8-b4a89da548-190c643f15.zip"; sha512 = "190c643f156d8f8f277bf2a6078af1ffde1fd43f498f187c2db24d35b4b4b5785c02c7dc52e356497b9a1b65b13edc996de08de0b961c32844364da02986dc53"; }; "@npmcli/arborist@npm:4.3.1" = { filename = "@npmcli-arborist-npm-4.3.1-68b2741cb0-51470ebb9a.zip"; sha512 = "51470ebb9a47c414822d1c05eda7dfef672848ddacf5734cc0575cc1a9f92cca32f17aac209d9e520424620a9ff4685db103f8b16953e2ef1823dfa2871b50e7"; }; "@npmcli/arborist@npm:5.3.0" = { filename = "@npmcli-arborist-npm-5.3.0-5f9b001b69-7f99f451ba.zip"; sha512 = "7f99f451ba625dd3532e7a69b27cc399cab1e7ef2a069bbc04cf22ef9d16a0076f8f5fb92c4cd146c256cd8a41963b2e417684f063a108e96939c440bad0e95e"; }; -"@npmcli/arborist@npm:6.2.1" = { filename = "@npmcli-arborist-npm-6.2.1-fdc5b09b0c-f0c2e7c46d.zip"; sha512 = "f0c2e7c46de5dbcf67e0756cb33eb435be608e1d536f2da644543993a987047dc0f4dee5aabdb901d232faab9236cbb19cbcd05fb30822442c283907de9517bd"; }; -"@npmcli/config@npm:6.1.2" = { filename = "@npmcli-config-npm-6.1.2-0573332f3c-2d9744c4a2.zip"; sha512 = "2d9744c4a2bf63df30253b36834b0b448f146ff15d649ff3473e4d449bf881a339b61c821ee8b5f7b5d991bb58a97a8bab668e80997528fbc799e94bbaa909b2"; }; +"@npmcli/arborist@npm:6.1.6" = { filename = "@npmcli-arborist-npm-6.1.6-6c8e7e9c94-dca822b38f.zip"; sha512 = "dca822b38f18d729d261123212952bef87334ede7816fa44a61cddb6990efbd583c8a90071cf2828390d750042bb619b57642c54fd850ccea9320b5391210d27"; }; +"@npmcli/config@npm:6.1.1" = { filename = "@npmcli-config-npm-6.1.1-7b86663e2d-bd9e9b30b0.zip"; sha512 = "bd9e9b30b0a66b0993e1719ed865f4d307bb18cac278b714ce0e6200c3039bdd216b2c3d38bec4ac642a72847ed4ce06bab4c591776627e13a1bb7cb4793d523"; }; "@npmcli/disparity-colors@npm:3.0.0" = { filename = "@npmcli-disparity-colors-npm-3.0.0-9fe9301a52-49320c6927.zip"; sha512 = "49320c6927b8e02a0eb006cfc9f5978370ae79ffa2b0da3b3d0ff2e9ef487501ebdec959dadc1e6f2725e16e27f9ea08f081a3af5126376f6f5b1caf6a1da0ce"; }; "@npmcli/fs@npm:1.1.1" = { filename = "@npmcli-fs-npm-1.1.1-17f582e0b6-f5ad92f157.zip"; sha512 = "f5ad92f157ed222e4e31c352333d0901df02c7c04311e42a81d8eb555d4ec4276ea9c635011757de20cc476755af33e91622838de573b17e52e2e7703f0a9965"; }; "@npmcli/fs@npm:2.1.2" = { filename = "@npmcli-fs-npm-2.1.2-08d434e77b-405074965e.zip"; sha512 = "405074965e72d4c9d728931b64d2d38e6ea12066d4fad651ac253d175e413c06fe4350970c783db0d749181da8fe49c42d3880bd1cbc12cd68e3a7964d820225"; }; @@ -1361,7 +1361,7 @@ cacheEntries = { "fs-extra@npm:9.1.0" = { filename = "fs-extra-npm-9.1.0-983c2ddb4c-ba71ba32e0.zip"; sha512 = "ba71ba32e0faa74ab931b7a0031d1523c66a73e225de7426e275e238e312d07313d2da2d33e34a52aa406c8763ade5712eb3ec9ba4d9edce652bcacdc29e6b20"; }; "fs-memo@npm:1.2.0" = { filename = "fs-memo-npm-1.2.0-274ddc7a4d-474c21adf4.zip"; sha512 = "474c21adf4510c60dc7e2a3c3ad1c08466c8bd276fcf9a8b5357fc03f48cb46a728a0e20c6146f6109db9f871015c8d5970cbbd1e4bdc8f0901e56a5318f8688"; }; "fs-minipass@npm:2.1.0" = { filename = "fs-minipass-npm-2.1.0-501ef87306-1b8d128dae.zip"; sha512 = "1b8d128dae2ac6cc94230cc5ead341ba3e0efaef82dab46a33d171c044caaa6ca001364178d42069b2809c35a1c3c35079a32107c770e9ffab3901b59af8c8b1"; }; -"fs-minipass@npm:3.0.1" = { filename = "fs-minipass-npm-3.0.1-c6a3dfa6c8-ce1fd3ccef.zip"; sha512 = "ce1fd3ccef7d64caa9ee5f566db1abe250b6e0067defe53003288537b310956e6f42c433c3ee6001e044f656ce8ba5a0b2e5b5589c513c67b57470d11c3d9b07"; }; +"fs-minipass@npm:3.0.0" = { filename = "fs-minipass-npm-3.0.0-3692c14b65-b72e9fe426.zip"; sha512 = "b72e9fe426e39f05b35bf237c8218b7ab3f68a65f325725ad7b4e431ff5a10725946fc62883b78446c07515ab938d25fdde3d08fb5ac8693f7f9eb9990da21f0"; }; "fs.realpath@npm:1.0.0" = { filename = "fs.realpath-npm-1.0.0-c8f05d8126-99ddea01a7.zip"; sha512 = "99ddea01a7e75aa276c250a04eedeffe5662bce66c65c07164ad6264f9de18fb21be9433ead460e54cff20e31721c811f4fb5d70591799df5f85dce6d6746fd0"; }; "fsevents@npm:2.3.2" = { filename = "fsevents-npm-2.3.2-a881d6ac9f-97ade64e75.zip"; sha512 = "97ade64e75091afee5265e6956cb72ba34db7819b4c3e94c431d4be2b19b8bb7a2d4116da417950c3425f17c8fe693d25e20212cac583ac1521ad066b77ae31f"; }; "ftp@npm:0.3.10" = { filename = "ftp-npm-0.3.10-348fb9ac23-ddd313c1d4.zip"; sha512 = "ddd313c1d44eb7429f3a7d77a0155dc8fe86a4c64dca58f395632333ce4b4e74c61413c6e0ef66ea3f3d32d905952fbb6d028c7117d522f793eb1fa282e17357"; }; @@ -1463,7 +1463,6 @@ cacheEntries = { "html-escaper@npm:2.0.2" = { filename = "html-escaper-npm-2.0.2-38e51ef294-d2df2da3ad.zip"; sha512 = "d2df2da3ad40ca9ee3a39c5cc6475ef67c8f83c234475f24d8e9ce0dc80a2c82df8e1d6fa78ddd1e9022a586ea1bd247a615e80a5cd9273d90111ddda7d9e974"; }; "htmlparser2@npm:8.0.1" = { filename = "htmlparser2-npm-8.0.1-b432299617-06d5c71e83.zip"; sha512 = "06d5c71e8313597722bc429ae2a7a8333d77bd3ab07ccb916628384b37332027b047f8619448d8f4a3312b6609c6ea3302a4e77435d859e9e686999e6699ca39"; }; "http-cache-semantics@npm:4.1.0" = { filename = "http-cache-semantics-npm-4.1.0-860520a31f-974de94a81.zip"; sha512 = "974de94a81c5474be07f269f9fd8383e92ebb5a448208223bfb39e172a9dbc26feff250192ecc23b9593b3f92098e010406b0f24bd4d588d631f80214648ed42"; }; -"http-cache-semantics@npm:4.1.1" = { filename = "http-cache-semantics-npm-4.1.1-1120131375-83ac0bc60b.zip"; sha512 = "83ac0bc60b17a3a36f9953e7be55e5c8f41acc61b22583060e8dedc9dd5e3607c823a88d0926f9150e571f90946835c7fe150732801010845c72cd8bbff1a236"; }; "http-call@npm:5.3.0" = { filename = "http-call-npm-5.3.0-f2c0703f3b-06e9342e1f.zip"; sha512 = "06e9342e1fc9d805ab666c862cac58ece953e0a72007410f4fba9aef40075f4c8bf0fdebbcfa1648433db05003ce1e00496ddb92e8dcff319a976638b2be4057"; }; "http-errors@npm:2.0.0" = { filename = "http-errors-npm-2.0.0-3f1c503428-9b0a378266.zip"; sha512 = "9b0a3782665c52ce9dc658a0d1560bcb0214ba5699e4ea15aefb2a496e2ca83db03ebc42e1cce4ac1f413e4e0d2d736a3fd755772c556a9a06853ba2a0b7d920"; }; "http-proxy-agent@npm:4.0.1" = { filename = "http-proxy-agent-npm-4.0.1-ce9ef61788-c6a5da5a19.zip"; sha512 = "c6a5da5a1929416b6bbdf77b1aca13888013fe7eb9d59fc292e25d18e041bb154a8dfada58e223fc7b76b9b2d155a87e92e608235201f77d34aa258707963a82"; }; @@ -1701,12 +1700,12 @@ cacheEntries = { "libhoney@npm:2.3.3" = { filename = "libhoney-npm-2.3.3-e739256257-29a382fb25.zip"; sha512 = "29a382fb25b16c35231bf4a99516c688d696efbe7702426effba88c68eaf659e4d597b3ba6eb927df378624643cb326050577607b3dcbc0167db637407ae85df"; }; "libnpmaccess@npm:6.0.4" = { filename = "libnpmaccess-npm-6.0.4-1b28cf19e9-86130b435c.zip"; sha512 = "86130b435c67a03254489c3b3684d435260b609164f76bcc69adbee78652c36a64551228b2c5ddc2b16851e9e367ee0ba173a641406768397716faa006042322"; }; "libnpmaccess@npm:7.0.1" = { filename = "libnpmaccess-npm-7.0.1-05fe791524-9250310027.zip"; sha512 = "92503100279233ba1b25225cfe1cc480a3dcbc1c633742de2221cd5eb44683076f17a60a91ee7b34477788429b88a57212c4624eb1f839f23e474be0563fcf4a"; }; -"libnpmdiff@npm:5.0.9" = { filename = "libnpmdiff-npm-5.0.9-d44c30193c-f7a464ad2f.zip"; sha512 = "f7a464ad2f4006d373616c68bb1f842779239390941ccb2c3455378d9c9ac8fee934d4684c671be5e2a65202b6d9f21460ddadbd1f2892c872a144daf969ec31"; }; -"libnpmexec@npm:5.0.9" = { filename = "libnpmexec-npm-5.0.9-aad05f79f9-573f0a6dde.zip"; sha512 = "573f0a6dde7886421ea9d8d07f664b28b5522420a9c1085537caf29725e61cd29df2e92748cbbec850c963913b362d0d6c5c97c033721c82d9becae1fcfb14c5"; }; -"libnpmfund@npm:4.0.9" = { filename = "libnpmfund-npm-4.0.9-e6a4b88cfc-dfeacc12d4.zip"; sha512 = "dfeacc12d477d65d80ec20260c2a7378fa909ca54a6188d682cfc01be24f49cdceca949edbfb579c2fde18caf9b3c09c18c530640d777841d0ffb8c6a1b6b45e"; }; +"libnpmdiff@npm:5.0.7" = { filename = "libnpmdiff-npm-5.0.7-5b21e7b8b7-175a42556a.zip"; sha512 = "175a42556afa517a361ac29a53d5bf0090aea864946a95502f3659ccfef2a3349ba3778d01339ca50d24dc6189f16fcce204920f918bf712d7b1c2a2a602a067"; }; +"libnpmexec@npm:5.0.7" = { filename = "libnpmexec-npm-5.0.7-09375d3b51-4267de0ef0.zip"; sha512 = "4267de0ef09a0e820976bae0a1a35ee8da76c3c34171db2e7e8adb39e956ab5542f5f6e276ca34eb1a2b4ee39c5f2b7fe1edc86a2fa9757974e6c9cf7e8b117b"; }; +"libnpmfund@npm:4.0.7" = { filename = "libnpmfund-npm-4.0.7-064c4558a9-918ee624cf.zip"; sha512 = "918ee624cfd9f7d1523fe7a1e980be8c1319346768ab30393d72a3fe85d89bdedcf206104383c2ba3e8bf937bd30ffa6844ffe618f1b907efcb51200bc5c56d1"; }; "libnpmhook@npm:9.0.1" = { filename = "libnpmhook-npm-9.0.1-d4fc9e3ab3-cca901e20f.zip"; sha512 = "cca901e20f9da832a925c95323d35aeebd2ca7f66f0d3e2ac2b6d0027688760b9cfd11cb1a75cfa501a1a5f4dd73995aaaada147c0a6a7e2ba68bbf563a3a7d9"; }; "libnpmorg@npm:5.0.1" = { filename = "libnpmorg-npm-5.0.1-15aa2365e9-072f0f15e5.zip"; sha512 = "072f0f15e5769db51f0d97af96f3347bf52e7ce82d044c733326329eedb1ad95d1fa950d239e06cc045b2724cda84cbfa89e4667396f353e01fecccb5d5a2b7a"; }; -"libnpmpack@npm:5.0.9" = { filename = "libnpmpack-npm-5.0.9-b6b1338c25-7d03c47473.zip"; sha512 = "7d03c4747353a06733846a4f82454782e06648325cfb46d302a3da4cdea961b60f7723fa8b68a146810a76b85440f11de08bb5228269575fb70ab345fe74d997"; }; +"libnpmpack@npm:5.0.7" = { filename = "libnpmpack-npm-5.0.7-629dfefdcd-efbafba4cf.zip"; sha512 = "efbafba4cf277fd1476d0e56e9a2abfad5e2ba85616040360b5dd7f1c39792042ad3ba6286dbf32e47e47f4b11c54bb4a6adc05c312980778d0ab6f03889b026"; }; "libnpmpublish@npm:6.0.5" = { filename = "libnpmpublish-npm-6.0.5-41d6654b18-d2f2434517.zip"; sha512 = "d2f2434517038438be44db2e90e1c8c524df05f7c3b1458617177c2f9ca008dde8a72a4f739b34aee4df0352f71c9289788da86aa38a4709e05c6db33eed570a"; }; "libnpmpublish@npm:7.0.6" = { filename = "libnpmpublish-npm-7.0.6-a5449a7ce0-0003e385af.zip"; sha512 = "0003e385af5b7e4f92f4a0667ba7cfb3a379ec43e310a4f3febefd81b87042cf12ab0ca91b9a36a2be05153930190056757532a2ab930123c1439ea5f0494a01"; }; "libnpmsearch@npm:6.0.1" = { filename = "libnpmsearch-npm-6.0.1-89dd34df86-6be998485f.zip"; sha512 = "6be998485f790bed481d738f74fa429d7a606cc6b8c1cf8d04281f3f8a56c1d5a8702ac967df7d07cd06d8794282849caa64988be49fbd36afb5419da3dcd80e"; }; @@ -1780,7 +1779,7 @@ cacheEntries = { "make-dir@npm:3.1.0" = { filename = "make-dir-npm-3.1.0-d1d7505142-484200020a.zip"; sha512 = "484200020ab5a1fdf12f393fe5f385fc8e4378824c940fba1729dcd198ae4ff24867bc7a5646331e50cead8abff5d9270c456314386e629acec6dff4b8016b78"; }; "make-error@npm:1.3.6" = { filename = "make-error-npm-1.3.6-ccb85d9458-b86e5e0e25.zip"; sha512 = "b86e5e0e25f7f777b77fabd8e2cbf15737972869d852a22b7e73c17623928fccb826d8e46b9951501d3f20e51ad74ba8c59ed584f610526a48f8ccf88aaec402"; }; "make-fetch-happen@npm:10.2.1" = { filename = "make-fetch-happen-npm-10.2.1-f1cc7cd2df-2332eb9a8e.zip"; sha512 = "2332eb9a8ec96f1ffeeea56ccefabcb4193693597b132cd110734d50f2928842e22b84cfa1508e921b8385cdfd06dda9ad68645fed62b50fff629a580f5fb72c"; }; -"make-fetch-happen@npm:11.0.3" = { filename = "make-fetch-happen-npm-11.0.3-c4a0fc8e55-f718d6b694.zip"; sha512 = "f718d6b6945d967fa02ae8c6b1146c6e36335b0f9654c5757fd57211a5bcc13bf1dfbaa0d2fdfe8bdd13f78b0e2aa79b4d4438f824dcf0d2ea74883baae1ae31"; }; +"make-fetch-happen@npm:11.0.2" = { filename = "make-fetch-happen-npm-11.0.2-17efd2b2ba-b843ef2e42.zip"; sha512 = "b843ef2e42bc17c37c7636dbe82867caceaa36b3f2591f20918abc190ca85cf37e5e142148b730dab7d94e9d2f0c80947a703f8dadebae993cd93ad929dba103"; }; "make-fetch-happen@npm:9.1.0" = { filename = "make-fetch-happen-npm-9.1.0-23184ad7f6-0eb371c85f.zip"; sha512 = "0eb371c85fdd0b1584fcfdf3dc3c62395761b3c14658be02620c310305a9a7ecf1617a5e6fb30c1d081c5c8aaf177fa133ee225024313afabb7aa6a10f1e3d04"; }; "makeerror@npm:1.0.12" = { filename = "makeerror-npm-1.0.12-69abf085d7-b38a025a12.zip"; sha512 = "b38a025a12c8146d6eeea5a7f2bf27d51d8ad6064da8ca9405fcf7bf9b54acd43e3b30ddd7abb9b1bfa4ddb266019133313482570ddb207de568f71ecfcf6060"; }; "map-obj@npm:1.0.1" = { filename = "map-obj-npm-1.0.1-fa55100fac-9949e7baec.zip"; sha512 = "9949e7baec2a336e63b8d4dc71018c117c3ce6e39d2451ccbfd3b8350c547c4f6af331a4cbe1c83193d7c6b786082b6256bde843db90cb7da2a21e8fcc28afed"; }; @@ -1831,7 +1830,7 @@ cacheEntries = { "minipass-pipeline@npm:1.2.4" = { filename = "minipass-pipeline-npm-1.2.4-5924cb077f-b14240dac0.zip"; sha512 = "b14240dac0d29823c3d5911c286069e36d0b81173d7bdf07a7e4a91ecdef92cdff4baaf31ea3746f1c61e0957f652e641223970870e2353593f382112257971b"; }; "minipass-sized@npm:1.0.3" = { filename = "minipass-sized-npm-1.0.3-306d86f432-79076749fc.zip"; sha512 = "79076749fcacf21b5d16dd596d32c3b6bf4d6e62abb43868fac21674078505c8b15eaca4e47ed844985a4514854f917d78f588fcd029693709417d8f98b2bd60"; }; "minipass@npm:3.3.5" = { filename = "minipass-npm-3.3.5-a555b091e7-f89f02bcaa.zip"; sha512 = "f89f02bcaa0e0e4bb4c44ec796008e69fbca62db0aba6ead1bc57d25bdaefdf42102130f4f9ecb7d9c6b6cd35ff7b0c7b97d001d3435da8e629fb68af3aea57e"; }; -"minipass@npm:4.0.1" = { filename = "minipass-npm-4.0.1-13cda48194-48eb3141cc.zip"; sha512 = "48eb3141cc247b44f738944cbd789aedeed9288ebdb64c7de9b3bf23e9e71d611381bfecf643d877d25f7ca9f3d5ab7b6757ef6f46282086812ac5372b7cd291"; }; +"minipass@npm:4.0.0" = { filename = "minipass-npm-4.0.0-2520d5ae3c-7a609afbf3.zip"; sha512 = "7a609afbf394abfcf9c48e6c90226f471676c8f2a67f07f6838871afb03215ede431d1433feffe1b855455bcb13ef0eb89162841b9796109d6fed8d89790f381"; }; "minizlib@npm:2.1.2" = { filename = "minizlib-npm-2.1.2-ea89cd0cfb-f1fdeac0b0.zip"; sha512 = "f1fdeac0b07cf8f30fcf12f4b586795b97be856edea22b5e9072707be51fc95d41487faec3f265b42973a304fe3a64acd91a44a3826a963e37b37bafde0212c3"; }; "mixpanel@npm:0.13.0" = { filename = "mixpanel-npm-0.13.0-da020f2419-b7486d763a.zip"; sha512 = "b7486d763aa8f57670e99590db0488bc722178b8844c0508d127c8f1b160fd36053e3e90f0cc11d0669dfd7778b170b3638200b481005c6583122ae343c5f069"; }; "mkdirp-classic@npm:0.5.3" = { filename = "mkdirp-classic-npm-0.5.3-3b5c991910-3f4e088208.zip"; sha512 = "3f4e088208270bbcc148d53b73e9a5bd9eef05ad2cbf3b3d0ff8795278d50dd1d11a8ef1875ff5aea3fa888931f95bfcb2ad5b7c1061cfefd6284d199e6776ac"; }; @@ -1926,7 +1925,7 @@ cacheEntries = { "npm-run-path@npm:4.0.1" = { filename = "npm-run-path-npm-4.0.1-7aebd8bab3-5374c0cea4.zip"; sha512 = "5374c0cea4b0bbfdfae62da7bbdf1e1558d338335f4cacf2515c282ff358ff27b2ecb91ffa5330a8b14390ac66a1e146e10700440c1ab868208430f56b5f4d23"; }; "npm-run-path@npm:5.1.0" = { filename = "npm-run-path-npm-5.1.0-79c0668d42-dc184eb5ec.zip"; sha512 = "dc184eb5ec239d6a2b990b43236845332ef12f4e0beaa9701de724aa797fe40b6bbd0157fb7639d24d3ab13f5d5cf22d223a19c6300846b8126f335f788bee66"; }; "npm-user-validate@npm:1.0.1" = { filename = "npm-user-validate-npm-1.0.1-337763b5fd-38ec7eb78a.zip"; sha512 = "38ec7eb78a0c001adc220798cd986592e03f6232f171af64c10c28fb5053d058d7f2748d1c42346338fa04fbeb5c0529f704cd5794aed1c33d303d978ac97b77"; }; -"npm@npm:9.4.1" = { filename = "npm-npm-9.4.1-14cc7c2f1d-fcac823b7c.zip"; sha512 = "fcac823b7c53d610a666d2b0c90f119a12a804b7eac0d1ccbb7c75dc22197e028273c5a01421216281f36e080eba4279102034cb9cb1866458cde5dde8fb02a0"; }; +"npm@npm:9.3.0" = { filename = "npm-npm-9.3.0-da6ad33933-b520eca5e8.zip"; sha512 = "b520eca5e88353496cceb16a608aafe2b979c6d8b239beca66b5c1ebfe62202573d00e556c3ecc13d34a6e355364611bff64c77bc982c31a11036ed364e8a05a"; }; "npmlog@npm:4.1.2" = { filename = "npmlog-npm-4.1.2-cfb32957b5-edbda9f95e.zip"; sha512 = "edbda9f95ec20957a892de1839afc6fb735054c3accf6fbefe767bac9a639fd5cea2baeac6bd2bcd50a85cb54924d57d9886c81c7fbc2332c2ddd19227504192"; }; "npmlog@npm:5.0.1" = { filename = "npmlog-npm-5.0.1-366cab64a2-516b266302.zip"; sha512 = "516b2663028761f062d13e8beb3f00069c5664925871a9b57989642ebe09f23ab02145bf3ab88da7866c4e112cafff72401f61a672c7c8a20edc585a7016ef5f"; }; "npmlog@npm:6.0.2" = { filename = "npmlog-npm-6.0.2-e0e69455c7-ae238cd264.zip"; sha512 = "ae238cd264a1c3f22091cdd9e2b106f684297d3c184f1146984ecbe18aaa86343953f26b9520dedd1b1372bc0316905b736c1932d778dbeb1fcf5a1001390e2a"; }; diff --git a/yarn.lock b/yarn.lock index 92691848d0c..57848d801ec 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2355,6 +2355,7 @@ __metadata: "@cardano-ogmios/client": 5.5.7 "@cardano-sdk/cardano-services-client": ^0.7.0 "@cardano-sdk/core": ^0.7.0 + "@cardano-sdk/crypto": ^0.1.0 "@cardano-sdk/ogmios": ^0.7.0 "@cardano-sdk/util": ^0.7.0 "@cardano-sdk/util-dev": ^0.6.0 @@ -2420,6 +2421,7 @@ __metadata: dependencies: "@cardano-ogmios/client": 5.5.7 "@cardano-ogmios/schema": 5.5.7 + "@cardano-sdk/crypto": ^0.1.0 "@cardano-sdk/util": ^0.7.0 "@dcspark/cardano-multiplatform-lib-nodejs": ^3.1.1 "@emurgo/cip14-js": ^3.0.1 @@ -2454,7 +2456,7 @@ __metadata: languageName: node linkType: hard -"@cardano-sdk/crypto@workspace:packages/crypto": +"@cardano-sdk/crypto@^0.1.0, @cardano-sdk/crypto@workspace:packages/crypto": version: 0.0.0-use.local resolution: "@cardano-sdk/crypto@workspace:packages/crypto" dependencies: @@ -2528,6 +2530,7 @@ __metadata: "@cardano-sdk/cardano-services": ^0.7.0 "@cardano-sdk/cardano-services-client": ^0.7.0 "@cardano-sdk/core": ^0.7.0 + "@cardano-sdk/crypto": ^0.1.0 "@cardano-sdk/dapp-connector": ^0.6.1 "@cardano-sdk/key-management": ^0.3.0 "@cardano-sdk/ogmios": ^0.7.0 @@ -2634,6 +2637,7 @@ __metadata: resolution: "@cardano-sdk/governance@workspace:packages/governance" dependencies: "@cardano-sdk/core": ^0.7.0 + "@cardano-sdk/crypto": ^0.1.0 "@cardano-sdk/key-management": ^0.3.0 "@cardano-sdk/util": ^0.7.0 blake2b: ^2.1.4 @@ -2676,8 +2680,10 @@ __metadata: dependencies: "@cardano-foundation/ledgerjs-hw-app-cardano": ^5.0.0 "@cardano-sdk/core": ^0.7.0 + "@cardano-sdk/crypto": ^0.1.0 "@cardano-sdk/dapp-connector": ^0.6.1 "@cardano-sdk/util": ^0.7.0 + "@cardano-sdk/util-dev": ^0.6.0 "@emurgo/cardano-message-signing-nodejs": ^1.0.1 "@ledgerhq/hw-transport": ^6.27.2 "@ledgerhq/hw-transport-node-hid-noevents": ^6.27.2 @@ -2710,6 +2716,7 @@ __metadata: "@cardano-ogmios/client": 5.5.7 "@cardano-ogmios/schema": 5.5.7 "@cardano-sdk/core": ^0.7.0 + "@cardano-sdk/crypto": ^0.1.0 "@cardano-sdk/util": ^0.7.0 "@cardano-sdk/util-dev": ^0.6.0 "@types/lodash": ^4.14.182 @@ -2734,6 +2741,7 @@ __metadata: resolution: "@cardano-sdk/projection@workspace:packages/projection" dependencies: "@cardano-sdk/core": ^0.7.0 + "@cardano-sdk/crypto": ^0.1.0 "@cardano-sdk/ogmios": ^0.7.0 "@cardano-sdk/util": ^0.7.0 "@cardano-sdk/util-dev": ^0.6.0 @@ -2848,6 +2856,7 @@ __metadata: "@cardano-foundation/ledgerjs-hw-app-cardano": ^5.0.0 "@cardano-ogmios/client": 5.5.7 "@cardano-sdk/core": ^0.7.0 + "@cardano-sdk/crypto": ^0.1.0 "@cardano-sdk/dapp-connector": ^0.6.1 "@cardano-sdk/input-selection": ^0.7.0 "@cardano-sdk/key-management": ^0.3.0 @@ -2886,6 +2895,7 @@ __metadata: resolution: "@cardano-sdk/web-extension@workspace:packages/web-extension" dependencies: "@cardano-sdk/core": ^0.7.0 + "@cardano-sdk/crypto": ^0.1.0 "@cardano-sdk/dapp-connector": ^0.6.1 "@cardano-sdk/key-management": ^0.3.0 "@cardano-sdk/util": ^0.7.0 @@ -4657,9 +4667,9 @@ __metadata: languageName: node linkType: hard -"@npmcli/arborist@npm:^6.2.1": - version: 6.2.1 - resolution: "@npmcli/arborist@npm:6.2.1" +"@npmcli/arborist@npm:^6.1.6": + version: 6.1.6 + resolution: "@npmcli/arborist@npm:6.1.6" dependencies: "@isaacs/string-locale-compare": ^1.1.0 "@npmcli/fs": ^3.1.0 @@ -4696,13 +4706,13 @@ __metadata: walk-up-path: ^1.0.0 bin: arborist: bin/index.js - checksum: f0c2e7c46de5dbcf67e0756cb33eb435be608e1d536f2da644543993a987047dc0f4dee5aabdb901d232faab9236cbb19cbcd05fb30822442c283907de9517bd + checksum: dca822b38f18d729d261123212952bef87334ede7816fa44a61cddb6990efbd583c8a90071cf2828390d750042bb619b57642c54fd850ccea9320b5391210d27 languageName: node linkType: hard -"@npmcli/config@npm:^6.1.2": - version: 6.1.2 - resolution: "@npmcli/config@npm:6.1.2" +"@npmcli/config@npm:^6.1.1": + version: 6.1.1 + resolution: "@npmcli/config@npm:6.1.1" dependencies: "@npmcli/map-workspaces": ^3.0.0 ini: ^3.0.0 @@ -4711,7 +4721,7 @@ __metadata: read-package-json-fast: ^3.0.0 semver: ^7.3.5 walk-up-path: ^1.0.0 - checksum: 2d9744c4a2bf63df30253b36834b0b448f146ff15d649ff3473e4d449bf881a339b61c821ee8b5f7b5d991bb58a97a8bab668e80997528fbc799e94bbaa909b2 + checksum: bd9e9b30b0a66b0993e1719ed865f4d307bb18cac278b714ce0e6200c3039bdd216b2c3d38bec4ac642a72847ed4ce06bab4c591776627e13a1bb7cb4793d523 languageName: node linkType: hard @@ -13438,11 +13448,11 @@ __metadata: linkType: hard "fs-minipass@npm:^3.0.0": - version: 3.0.1 - resolution: "fs-minipass@npm:3.0.1" + version: 3.0.0 + resolution: "fs-minipass@npm:3.0.0" dependencies: minipass: ^4.0.0 - checksum: ce1fd3ccef7d64caa9ee5f566db1abe250b6e0067defe53003288537b310956e6f42c433c3ee6001e044f656ce8ba5a0b2e5b5589c513c67b57470d11c3d9b07 + checksum: b72e9fe426e39f05b35bf237c8218b7ab3f68a65f325725ad7b4e431ff5a10725946fc62883b78446c07515ab938d25fdde3d08fb5ac8693f7f9eb9990da21f0 languageName: node linkType: hard @@ -14445,13 +14455,6 @@ __metadata: languageName: node linkType: hard -"http-cache-semantics@npm:^4.1.1": - version: 4.1.1 - resolution: "http-cache-semantics@npm:4.1.1" - checksum: 83ac0bc60b17a3a36f9953e7be55e5c8f41acc61b22583060e8dedc9dd5e3607c823a88d0926f9150e571f90946835c7fe150732801010845c72cd8bbff1a236 - languageName: node - linkType: hard - "http-call@npm:^5.1.2, http-call@npm:^5.2.2": version: 5.3.0 resolution: "http-call@npm:5.3.0" @@ -16825,11 +16828,11 @@ __metadata: languageName: node linkType: hard -"libnpmdiff@npm:^5.0.9": - version: 5.0.9 - resolution: "libnpmdiff@npm:5.0.9" +"libnpmdiff@npm:^5.0.7": + version: 5.0.7 + resolution: "libnpmdiff@npm:5.0.7" dependencies: - "@npmcli/arborist": ^6.2.1 + "@npmcli/arborist": ^6.1.6 "@npmcli/disparity-colors": ^3.0.0 "@npmcli/installed-package-contents": ^2.0.0 binary-extensions: ^2.2.0 @@ -16838,15 +16841,15 @@ __metadata: npm-package-arg: ^10.1.0 pacote: ^15.0.7 tar: ^6.1.13 - checksum: f7a464ad2f4006d373616c68bb1f842779239390941ccb2c3455378d9c9ac8fee934d4684c671be5e2a65202b6d9f21460ddadbd1f2892c872a144daf969ec31 + checksum: 175a42556afa517a361ac29a53d5bf0090aea864946a95502f3659ccfef2a3349ba3778d01339ca50d24dc6189f16fcce204920f918bf712d7b1c2a2a602a067 languageName: node linkType: hard -"libnpmexec@npm:^5.0.9": - version: 5.0.9 - resolution: "libnpmexec@npm:5.0.9" +"libnpmexec@npm:^5.0.7": + version: 5.0.7 + resolution: "libnpmexec@npm:5.0.7" dependencies: - "@npmcli/arborist": ^6.2.1 + "@npmcli/arborist": ^6.1.6 "@npmcli/run-script": ^6.0.0 chalk: ^4.1.0 ci-info: ^3.7.0 @@ -16858,16 +16861,16 @@ __metadata: read-package-json-fast: ^3.0.1 semver: ^7.3.7 walk-up-path: ^1.0.0 - checksum: 573f0a6dde7886421ea9d8d07f664b28b5522420a9c1085537caf29725e61cd29df2e92748cbbec850c963913b362d0d6c5c97c033721c82d9becae1fcfb14c5 + checksum: 4267de0ef09a0e820976bae0a1a35ee8da76c3c34171db2e7e8adb39e956ab5542f5f6e276ca34eb1a2b4ee39c5f2b7fe1edc86a2fa9757974e6c9cf7e8b117b languageName: node linkType: hard -"libnpmfund@npm:^4.0.9": - version: 4.0.9 - resolution: "libnpmfund@npm:4.0.9" +"libnpmfund@npm:^4.0.7": + version: 4.0.7 + resolution: "libnpmfund@npm:4.0.7" dependencies: - "@npmcli/arborist": ^6.2.1 - checksum: dfeacc12d477d65d80ec20260c2a7378fa909ca54a6188d682cfc01be24f49cdceca949edbfb579c2fde18caf9b3c09c18c530640d777841d0ffb8c6a1b6b45e + "@npmcli/arborist": ^6.1.6 + checksum: 918ee624cfd9f7d1523fe7a1e980be8c1319346768ab30393d72a3fe85d89bdedcf206104383c2ba3e8bf937bd30ffa6844ffe618f1b907efcb51200bc5c56d1 languageName: node linkType: hard @@ -16891,15 +16894,15 @@ __metadata: languageName: node linkType: hard -"libnpmpack@npm:^5.0.9": - version: 5.0.9 - resolution: "libnpmpack@npm:5.0.9" +"libnpmpack@npm:^5.0.7": + version: 5.0.7 + resolution: "libnpmpack@npm:5.0.7" dependencies: - "@npmcli/arborist": ^6.2.1 + "@npmcli/arborist": ^6.1.6 "@npmcli/run-script": ^6.0.0 npm-package-arg: ^10.1.0 pacote: ^15.0.7 - checksum: 7d03c4747353a06733846a4f82454782e06648325cfb46d302a3da4cdea961b60f7723fa8b68a146810a76b85440f11de08bb5228269575fb70ab345fe74d997 + checksum: efbafba4cf277fd1476d0e56e9a2abfad5e2ba85616040360b5dd7f1c39792042ad3ba6286dbf32e47e47f4b11c54bb4a6adc05c312980778d0ab6f03889b026 languageName: node linkType: hard @@ -17588,17 +17591,18 @@ __metadata: linkType: hard "make-fetch-happen@npm:^11.0.0, make-fetch-happen@npm:^11.0.2": - version: 11.0.3 - resolution: "make-fetch-happen@npm:11.0.3" + version: 11.0.2 + resolution: "make-fetch-happen@npm:11.0.2" dependencies: agentkeepalive: ^4.2.1 cacache: ^17.0.0 - http-cache-semantics: ^4.1.1 + http-cache-semantics: ^4.1.0 http-proxy-agent: ^5.0.0 https-proxy-agent: ^5.0.0 is-lambda: ^1.0.1 lru-cache: ^7.7.1 minipass: ^4.0.0 + minipass-collect: ^1.0.2 minipass-fetch: ^3.0.0 minipass-flush: ^1.0.5 minipass-pipeline: ^1.2.4 @@ -17606,7 +17610,7 @@ __metadata: promise-retry: ^2.0.1 socks-proxy-agent: ^7.0.0 ssri: ^10.0.0 - checksum: f718d6b6945d967fa02ae8c6b1146c6e36335b0f9654c5757fd57211a5bcc13bf1dfbaa0d2fdfe8bdd13f78b0e2aa79b4d4438f824dcf0d2ea74883baae1ae31 + checksum: b843ef2e42bc17c37c7636dbe82867caceaa36b3f2591f20918abc190ca85cf37e5e142148b730dab7d94e9d2f0c80947a703f8dadebae993cd93ad929dba103 languageName: node linkType: hard @@ -18089,9 +18093,11 @@ __metadata: linkType: hard "minipass@npm:^4.0.0": - version: 4.0.1 - resolution: "minipass@npm:4.0.1" - checksum: 48eb3141cc247b44f738944cbd789aedeed9288ebdb64c7de9b3bf23e9e71d611381bfecf643d877d25f7ca9f3d5ab7b6757ef6f46282086812ac5372b7cd291 + version: 4.0.0 + resolution: "minipass@npm:4.0.0" + dependencies: + yallist: ^4.0.0 + checksum: 7a609afbf394abfcf9c48e6c90226f471676c8f2a67f07f6838871afb03215ede431d1433feffe1b855455bcb13ef0eb89162841b9796109d6fed8d89790f381 languageName: node linkType: hard @@ -19090,12 +19096,12 @@ __metadata: linkType: hard "npm@npm:^9.3.0": - version: 9.4.1 - resolution: "npm@npm:9.4.1" + version: 9.3.0 + resolution: "npm@npm:9.3.0" dependencies: "@isaacs/string-locale-compare": ^1.1.0 - "@npmcli/arborist": ^6.2.1 - "@npmcli/config": ^6.1.2 + "@npmcli/arborist": ^6.1.6 + "@npmcli/config": ^6.1.1 "@npmcli/map-workspaces": ^3.0.0 "@npmcli/package-json": ^3.0.0 "@npmcli/run-script": ^6.0.0 @@ -19117,12 +19123,12 @@ __metadata: is-cidr: ^4.0.2 json-parse-even-better-errors: ^3.0.0 libnpmaccess: ^7.0.1 - libnpmdiff: ^5.0.9 - libnpmexec: ^5.0.9 - libnpmfund: ^4.0.9 + libnpmdiff: ^5.0.7 + libnpmexec: ^5.0.7 + libnpmfund: ^4.0.7 libnpmhook: ^9.0.1 libnpmorg: ^5.0.1 - libnpmpack: ^5.0.9 + libnpmpack: ^5.0.7 libnpmpublish: ^7.0.6 libnpmsearch: ^6.0.1 libnpmteam: ^5.0.1 @@ -19163,7 +19169,7 @@ __metadata: bin: npm: bin/npm-cli.js npx: bin/npx-cli.js - checksum: fcac823b7c53d610a666d2b0c90f119a12a804b7eac0d1ccbb7c75dc22197e028273c5a01421216281f36e080eba4279102034cb9cb1866458cde5dde8fb02a0 + checksum: b520eca5e88353496cceb16a608aafe2b979c6d8b239beca66b5c1ebfe62202573d00e556c3ecc13d34a6e355364611bff64c77bc982c31a11036ed364e8a05a languageName: node linkType: hard