diff --git a/packages/txwrapper-core/src/core/construct/createSignedTx.spec.ts b/packages/txwrapper-core/src/core/construct/createSignedTx.spec.ts index 36c79462..658e754f 100644 --- a/packages/txwrapper-core/src/core/construct/createSignedTx.spec.ts +++ b/packages/txwrapper-core/src/core/construct/createSignedTx.spec.ts @@ -4,6 +4,7 @@ import { ASTAR_TEST_OPTIONS, KUSAMA_TEST_OPTIONS, signWithAlice, + signWithAliceAstar, TEST_BASE_TX_INFO, TEST_METHOD_ARGS, } from '@substrate/txwrapper-dev'; @@ -38,7 +39,7 @@ describe('createSignedTx', () => { ASTAR_TEST_OPTIONS, ); const signingPayload = createSigningPayload(unsigned, ASTAR_TEST_OPTIONS); - const signature = await signWithAlice(signingPayload); + const signature = await signWithAliceAstar(signingPayload); const tx = createSignedTx(unsigned, signature, ASTAR_TEST_OPTIONS); expect(tx).toBe( diff --git a/packages/txwrapper-core/src/core/construct/getTxHash.spec.ts b/packages/txwrapper-core/src/core/construct/getTxHash.spec.ts index f712d174..a24a04c9 100644 --- a/packages/txwrapper-core/src/core/construct/getTxHash.spec.ts +++ b/packages/txwrapper-core/src/core/construct/getTxHash.spec.ts @@ -4,6 +4,7 @@ import { ASTAR_TEST_OPTIONS, KUSAMA_TEST_OPTIONS, signWithAlice, + signWithAliceAstar, TEST_BASE_TX_INFO, TEST_METHOD_ARGS, } from '@substrate/txwrapper-dev'; @@ -49,7 +50,7 @@ describe('getTxHash', () => { unsigned, ASTAR_TEST_OPTIONS, ); - const signature = await signWithAlice(signingPayload); + const signature = await signWithAliceAstar(signingPayload); const signedTx = construct.signedTx( unsigned, signature, @@ -58,7 +59,7 @@ describe('getTxHash', () => { const txHash = getTxHash(signedTx); expect(txHash).toBe( - '0x48598a4b920b83b931777088e6d1c9bcc1466518cb1ae0faa2a29553798e2f9c', + '0x1fc108525d6569889d53cbc092cba9c7ad0f59d668c60eff3447c774815d0485', ); }); }); diff --git a/packages/txwrapper-core/src/core/decode/decodeSignedTx.spec.ts b/packages/txwrapper-core/src/core/decode/decodeSignedTx.spec.ts index 39f592b7..36621b8a 100644 --- a/packages/txwrapper-core/src/core/decode/decodeSignedTx.spec.ts +++ b/packages/txwrapper-core/src/core/decode/decodeSignedTx.spec.ts @@ -4,6 +4,7 @@ import { ASTAR_TEST_OPTIONS, KUSAMA_TEST_OPTIONS, signWithAlice, + signWithAliceAstar, TEST_BASE_TX_INFO, TEST_METHOD_ARGS, } from '@substrate/txwrapper-dev'; @@ -69,7 +70,7 @@ describe('decodeSignedTx', () => { unsigned, ASTAR_TEST_OPTIONS, ); - const signature = await signWithAlice(signingPayload); + const signature = await signWithAliceAstar(signingPayload); const signedTx = construct.signedTx( unsigned, signature, diff --git a/packages/txwrapper-dev/src/util/index.ts b/packages/txwrapper-dev/src/util/index.ts index 1cd9421d..df8e13c3 100644 --- a/packages/txwrapper-dev/src/util/index.ts +++ b/packages/txwrapper-dev/src/util/index.ts @@ -1,2 +1,3 @@ export * from './knownChainProperties'; export * from './signWithAlice'; +export * from './signWithAliceAstar'; diff --git a/packages/txwrapper-dev/src/util/signWithAliceAstar.ts b/packages/txwrapper-dev/src/util/signWithAliceAstar.ts new file mode 100644 index 00000000..3ddca82e --- /dev/null +++ b/packages/txwrapper-dev/src/util/signWithAliceAstar.ts @@ -0,0 +1,26 @@ +import { Keyring } from '@polkadot/api'; +import { cryptoWaitReady } from '@polkadot/util-crypto'; + +import { ASTAR_TEST_OPTIONS } from '../constants'; + +/** + * Sign a payload with seed `//Alice`. + */ +export async function signWithAliceAstar( + signingPayload: string, +): Promise<`0x${string}`> { + // We're creating an Alice account that will sign the payload + // Wait for the promise to resolve async WASM + await cryptoWaitReady(); + // Use ed25519 because it has deterministic signatures + const keyring = new Keyring({ type: 'ed25519' }); + const alice = keyring.addFromUri('//Alice', { name: 'Alice default' }); + + const { signature } = ASTAR_TEST_OPTIONS.registry + .createType('ExtrinsicPayload', signingPayload, { + version: 4, + }) + .sign(alice); + + return signature; +}