createSignedTx.ts 907 Bytes
Newer Older
Amaury Martiny's avatar
Amaury Martiny committed
1
import { createType, Metadata, TypeRegistry } from '@polkadot/types';
2
3
4
5

import { UnsignedTransaction } from './balanceTransfer';

/**
Amaury Martiny's avatar
Amaury Martiny committed
6
7
8
9
 * Serialize a signed transaction in a format that can be submitted over the
 * Node RPC Interface from the signing payload and signature produced by the
 * remote signer

10
11
 *
 * @param unsigned - The JSON representing the unsigned transaction
Amaury Martiny's avatar
Amaury Martiny committed
12
13
 * @param signature - Signature of the signing payload produced by the remote
 * signer
14
15
16
 */
export function createSignedTx(
  unsigned: UnsignedTransaction,
17
  signature: string
18
19
): string {
  const registry = new TypeRegistry();
20
  registry.setMetadata(new Metadata(registry, unsigned.metadataRpc));
21
22
23
24
25
26
27
28
29
30
31
32

  const extrinsic = createType(
    registry,
    'Extrinsic',
    { method: unsigned.method },
    { version: unsigned.version }
  );

  extrinsic.addSignature(unsigned.address, signature, unsigned);

  return extrinsic.toHex();
}