-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
index.ts
37 lines (29 loc) · 1005 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
29
30
31
32
33
34
35
36
37
/* eslint-disable max-classes-per-file */
import { hexlify } from '@ethersproject/bytes';
import type { BytesLike } from '@ethersproject/bytes';
export type Address = string;
export type ContractId = string;
export abstract class AbstractScript<T> {
abstract bytes: Uint8Array;
abstract encodeScriptData: (data: T) => Uint8Array;
}
export abstract class AbstractContract {
abstract id: ContractId;
}
export abstract class AbstractWallet {
abstract address: string;
}
export type AddressLike = Address | BytesLike | AbstractWallet;
export const addressify = (addressLike: AddressLike): Address => {
if (addressLike instanceof AbstractWallet) {
return addressLike.address;
}
return hexlify(addressLike);
};
export type ContractIdLike = ContractId | BytesLike | AbstractContract;
export const contractIdify = (contractIdLike: ContractIdLike): ContractId => {
if (contractIdLike instanceof AbstractContract) {
return contractIdLike.id;
}
return hexlify(contractIdLike);
};