-
Notifications
You must be signed in to change notification settings - Fork 59
/
index.ts
28 lines (26 loc) · 924 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { Encoded, Encoding } from '../../../utils/encoder';
import { packRecord, unpackRecord } from '../common';
import { DelegationTag, schemas } from './schema';
import { DlgParams, DlgUnpacked } from './schema.generated';
/**
* Pack delegation
* @category delegation signature
* @param params - Params of delegation
* @returns Encoded delegation
*/
export function packDelegation(params: DlgParams): Encoded.Bytearray {
return packRecord(schemas, DelegationTag, params, {}, Encoding.Bytearray);
}
/**
* Unpack delegation
* @category delegation signature
* @param encoded - Encoded delegation
* @param expectedTag - Expected delegation signature type
* @returns Params of delegation
*/
export function unpackDelegation<T extends DelegationTag>(
encoded: Encoded.Bytearray,
expectedTag?: T,
): DlgUnpacked & { tag: T } {
return unpackRecord(schemas, DelegationTag, encoded, expectedTag, {}) as any;
}