@frequency-chain/ethereum-utils 1.17.0-rc4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts ADDED
@@ -0,0 +1,85 @@
1
+ import * as payloads from './payloads';
2
+ export * from './payloads';
3
+ export * from './signature';
4
+ export * from './signature.definitions';
5
+ export * from './address';
6
+ declare const _default: {
7
+ signEip712(secretKey: payloads.HexString, payload: payloads.SupportedPayload, chain?: payloads.ChainType): Promise<payloads.EcdsaSignature>;
8
+ verifyEip712Signature(ethereumAddress: payloads.HexString, signature: payloads.HexString, payload: payloads.SupportedPayload, chain?: payloads.ChainType): boolean;
9
+ createAddKeyData(msaId: string | bigint, newPublicKey: payloads.HexString | Uint8Array, expirationBlock: number): payloads.AddKeyData;
10
+ createAddProvider(authorizedMsaId: string | bigint, schemaIds: number[], expirationBlock: number): payloads.AddProvider;
11
+ createClaimHandlePayload(handle: string, expirationBlock: number): payloads.ClaimHandlePayload;
12
+ createPasskeyPublicKey(publicKey: payloads.HexString | Uint8Array): payloads.PasskeyPublicKey;
13
+ createItemizedAddAction(data: payloads.HexString | Uint8Array): payloads.AddItemizedAction;
14
+ createItemizedDeleteAction(index: number): payloads.DeleteItemizedAction;
15
+ createItemizedSignaturePayloadV2(schemaId: number, targetHash: number, expiration: number, actions: payloads.ItemizedAction[]): payloads.ItemizedSignaturePayloadV2;
16
+ createPaginatedDeleteSignaturePayloadV2(schemaId: number, pageId: number, targetHash: number, expiration: number): payloads.PaginatedDeleteSignaturePayloadV2;
17
+ createPaginatedUpsertSignaturePayloadV2(schemaId: number, pageId: number, targetHash: number, expiration: number, payload: payloads.HexString | Uint8Array): payloads.PaginatedUpsertSignaturePayloadV2;
18
+ getEip712BrowserRequestAddKeyData(msaId: string | bigint, newPublicKey: payloads.HexString | Uint8Array, expirationBlock: number, domain?: payloads.EipDomainPayload): unknown;
19
+ getEip712BrowserRequestAddProvider(authorizedMsaId: string | bigint, schemaIds: number[], expirationBlock: number, domain?: payloads.EipDomainPayload): unknown;
20
+ getEip712BrowserRequestPaginatedUpsertSignaturePayloadV2(schemaId: number, pageId: number, targetHash: number, expiration: number, payload: payloads.HexString | Uint8Array, domain?: payloads.EipDomainPayload): unknown;
21
+ getEip712BrowserRequestPaginatedDeleteSignaturePayloadV2(schemaId: number, pageId: number, targetHash: number, expiration: number, domain?: payloads.EipDomainPayload): unknown;
22
+ getEip712BrowserRequestItemizedSignaturePayloadV2(schemaId: number, targetHash: number, expiration: number, actions: payloads.ItemizedAction[], domain?: payloads.EipDomainPayload): unknown;
23
+ getEip712BrowserRequestClaimHandlePayload(handle: string, expirationBlock: number, domain?: payloads.EipDomainPayload): unknown;
24
+ getEip712BrowserRequestPasskeyPublicKey(publicKey: payloads.HexString | Uint8Array, domain?: payloads.EipDomainPayload): unknown;
25
+ EIP712_DOMAIN_DEFINITION: {
26
+ EIP712Domain: {
27
+ name: string;
28
+ type: string;
29
+ }[];
30
+ };
31
+ EIP712_DOMAIN_DEFAULT: payloads.EipDomainPayload;
32
+ ADD_PROVIDER_DEFINITION: {
33
+ AddProvider: {
34
+ name: string;
35
+ type: string;
36
+ }[];
37
+ };
38
+ ADD_KEY_DATA_DEFINITION: {
39
+ AddKeyData: {
40
+ name: string;
41
+ type: string;
42
+ }[];
43
+ };
44
+ CLAIM_HANDLE_PAYLOAD_DEFINITION: {
45
+ ClaimHandlePayload: {
46
+ name: string;
47
+ type: string;
48
+ }[];
49
+ };
50
+ PASSKEY_PUBLIC_KEY_DEFINITION: {
51
+ PasskeyPublicKey: {
52
+ name: string;
53
+ type: string;
54
+ }[];
55
+ };
56
+ PAGINATED_DELETE_SIGNATURE_PAYLOAD_DEFINITION_V2: {
57
+ PaginatedDeleteSignaturePayloadV2: {
58
+ name: string;
59
+ type: string;
60
+ }[];
61
+ };
62
+ PAGINATED_UPSERT_SIGNATURE_PAYLOAD_DEFINITION_V2: {
63
+ PaginatedUpsertSignaturePayloadV2: {
64
+ name: string;
65
+ type: string;
66
+ }[];
67
+ };
68
+ ITEMIZED_SIGNATURE_PAYLOAD_DEFINITION_V2: {
69
+ ItemizedSignaturePayloadV2: {
70
+ name: string;
71
+ type: string;
72
+ }[];
73
+ ItemAction: {
74
+ name: string;
75
+ type: string;
76
+ }[];
77
+ };
78
+ createRandomKey(): payloads.EthereumKeyPair;
79
+ ethereumAddressToKeyringPair(ethereumAddress: import("@polkadot/types/interfaces").H160): import("@polkadot/keyring/types").KeyringPair;
80
+ getUnifiedAddress(pair: import("@polkadot/keyring/types").KeyringPair): string;
81
+ getUnifiedPublicKey(pair: import("@polkadot/keyring/types").KeyringPair): Uint8Array;
82
+ reverseUnifiedAddressToEthereumAddress(unifiedAddress: payloads.HexString): payloads.HexString;
83
+ getSS58AccountFromEthereumAccount(accountId20Hex: string): string;
84
+ };
85
+ export default _default;
package/package.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@frequency-chain/ethereum-utils",
3
+ "version": "1.17.0-rc4",
4
+ "bugs": {
5
+ "url": "https://github.com/frequency-chain/frequency/issues"
6
+ },
7
+ "description": "A package which facilitates use of Ethereum addresses, signatures and standards with Frequency chain.",
8
+ "main": "./cjs/index.js",
9
+ "type": "module",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/frequency-chain/frequency.git",
13
+ "directory": "js/ethereum-utils"
14
+ },
15
+ "author": "frequency-chain",
16
+ "license": "Apache-2.0",
17
+ "dependencies": {
18
+ "@polkadot/api": "^15.10.2",
19
+ "@polkadot/util": "13.4.4",
20
+ "ethers": "^6.14.0"
21
+ },
22
+ "module": "./esm/index.js",
23
+ "types": "index.d.ts",
24
+ "exports": {
25
+ ".": {
26
+ "types": "./index.d.ts",
27
+ "require": "./cjs/index.js",
28
+ "import": "./esm/index.js",
29
+ "default": "./esm/index.js"
30
+ }
31
+ }
32
+ }
package/payloads.d.ts ADDED
@@ -0,0 +1,77 @@
1
+ export type HexString = `0x${string}`;
2
+ export interface EcdsaSignature {
3
+ Ecdsa: HexString;
4
+ }
5
+ export type ChainType = 'Mainnet-Frequency' | 'Paseo-Testnet-Frequency' | 'Dev';
6
+ export interface AddressWrapper {
7
+ ethereumAddress: HexString;
8
+ unifiedAddress: HexString;
9
+ unifiedAddressSS58: string;
10
+ }
11
+ export interface EthereumKeyPair {
12
+ privateKey: HexString;
13
+ publicKey: HexString;
14
+ address: AddressWrapper;
15
+ mnemonic: string;
16
+ }
17
+ export interface PaginatedUpsertSignaturePayloadV2 {
18
+ type: 'PaginatedUpsertSignaturePayloadV2';
19
+ schemaId: number;
20
+ pageId: number;
21
+ targetHash: number;
22
+ expiration: number;
23
+ payload: HexString;
24
+ }
25
+ export interface PaginatedDeleteSignaturePayloadV2 {
26
+ type: 'PaginatedDeleteSignaturePayloadV2';
27
+ schemaId: number;
28
+ pageId: number;
29
+ targetHash: number;
30
+ expiration: number;
31
+ }
32
+ export interface AddItemizedAction {
33
+ actionType: 'Add';
34
+ data: HexString;
35
+ index: 0;
36
+ }
37
+ export interface DeleteItemizedAction {
38
+ actionType: 'Delete';
39
+ data: '0x';
40
+ index: number;
41
+ }
42
+ export type ItemizedAction = AddItemizedAction | DeleteItemizedAction;
43
+ export interface ItemizedSignaturePayloadV2 {
44
+ type: 'ItemizedSignaturePayloadV2';
45
+ schemaId: number;
46
+ targetHash: number;
47
+ expiration: number;
48
+ actions: ItemizedAction[];
49
+ }
50
+ export interface PasskeyPublicKey {
51
+ type: 'PasskeyPublicKey';
52
+ publicKey: HexString;
53
+ }
54
+ export interface ClaimHandlePayload {
55
+ type: 'ClaimHandlePayload';
56
+ handle: string;
57
+ expiration: number;
58
+ }
59
+ export interface AddKeyData {
60
+ type: 'AddKeyData';
61
+ msaId: string;
62
+ expiration: number;
63
+ newPublicKey: HexString;
64
+ }
65
+ export interface AddProvider {
66
+ type: 'AddProvider';
67
+ authorizedMsaId: string;
68
+ schemaIds: number[];
69
+ expiration: number;
70
+ }
71
+ export type SupportedPayload = PaginatedUpsertSignaturePayloadV2 | PaginatedDeleteSignaturePayloadV2 | ItemizedSignaturePayloadV2 | PasskeyPublicKey | ClaimHandlePayload | AddKeyData | AddProvider;
72
+ export interface EipDomainPayload {
73
+ name: string;
74
+ version: string;
75
+ chainId: HexString;
76
+ verifyingContract: HexString;
77
+ }
package/signature.d.ts ADDED
@@ -0,0 +1,139 @@
1
+ import { AddKeyData, AddProvider, ChainType, ClaimHandlePayload, EcdsaSignature, ItemizedSignaturePayloadV2, PaginatedDeleteSignaturePayloadV2, PaginatedUpsertSignaturePayloadV2, PasskeyPublicKey, SupportedPayload, HexString, AddItemizedAction, DeleteItemizedAction, ItemizedAction, EipDomainPayload } from './payloads';
2
+ /**
3
+ * Signing EIP-712 compatible signature for payload
4
+ * @param secretKey
5
+ * @param payload
6
+ * @param chain
7
+ */
8
+ export declare function signEip712(secretKey: HexString, payload: SupportedPayload, chain?: ChainType): Promise<EcdsaSignature>;
9
+ /**
10
+ * Verify EIP-712 signatures
11
+ * @param ethereumAddress
12
+ * @param signature
13
+ * @param payload
14
+ * @param chain
15
+ */
16
+ export declare function verifyEip712Signature(ethereumAddress: HexString, signature: HexString, payload: SupportedPayload, chain?: ChainType): boolean;
17
+ /**
18
+ * Build an AddKeyData payload for signature.
19
+ *
20
+ * @param msaId MSA ID (uint64) to add the key
21
+ * @param newPublicKey 32 bytes public key to add in hex or Uint8Array
22
+ * @param expirationBlock Block number after which this payload is invalid
23
+ */
24
+ export declare function createAddKeyData(msaId: string | bigint, newPublicKey: HexString | Uint8Array, expirationBlock: number): AddKeyData;
25
+ /**
26
+ * Build an AddProvider payload for signature.
27
+ *
28
+ * @param authorizedMsaId MSA ID (uint64) that will be granted provider rights
29
+ * @param schemaIds One or more schema IDs (uint16) the provider may use
30
+ * @param expirationBlock Block number after which this payload is invalid
31
+ */
32
+ export declare function createAddProvider(authorizedMsaId: string | bigint, schemaIds: number[], expirationBlock: number): AddProvider;
33
+ /**
34
+ * Build a ClaimHandlePayload for signature.
35
+ *
36
+ * @param handle The handle the user wishes to claim
37
+ * @param expirationBlock Block number after which this payload is invalid
38
+ */
39
+ export declare function createClaimHandlePayload(handle: string, expirationBlock: number): ClaimHandlePayload;
40
+ /**
41
+ * Build a PasskeyPublicKey payload for signature.
42
+ *
43
+ * @param publicKey The passkey’s public key (hex string or raw bytes)
44
+ */
45
+ export declare function createPasskeyPublicKey(publicKey: HexString | Uint8Array): PasskeyPublicKey;
46
+ export declare function createItemizedAddAction(data: HexString | Uint8Array): AddItemizedAction;
47
+ export declare function createItemizedDeleteAction(index: number): DeleteItemizedAction;
48
+ /**
49
+ * Build an ItemizedSignaturePayloadV2 for signing.
50
+ *
51
+ * @param schemaId uint16 schema identifier
52
+ * @param targetHash uint32 page hash
53
+ * @param expiration uint32 expiration block
54
+ * @param actions Array of Add/Delete itemized actions
55
+ */
56
+ export declare function createItemizedSignaturePayloadV2(schemaId: number, targetHash: number, expiration: number, actions: ItemizedAction[]): ItemizedSignaturePayloadV2;
57
+ /**
58
+ * Build a PaginatedDeleteSignaturePayloadV2 for signing.
59
+ *
60
+ * @param schemaId uint16 schema identifier
61
+ * @param pageId uint16 page identifier
62
+ * @param targetHash uint32 page hash
63
+ * @param expiration uint32 expiration block
64
+ */
65
+ export declare function createPaginatedDeleteSignaturePayloadV2(schemaId: number, pageId: number, targetHash: number, expiration: number): PaginatedDeleteSignaturePayloadV2;
66
+ /**
67
+ * Build a PaginatedUpsertSignaturePayloadV2 for signing.
68
+ *
69
+ * @param schemaId uint16 schema identifier
70
+ * @param pageId uint16 page identifier
71
+ * @param targetHash uint32 page hash
72
+ * @param expiration uint32 expiration block
73
+ * @param payload HexString or Uint8Array data to upsert
74
+ */
75
+ export declare function createPaginatedUpsertSignaturePayloadV2(schemaId: number, pageId: number, targetHash: number, expiration: number, payload: HexString | Uint8Array): PaginatedUpsertSignaturePayloadV2;
76
+ /**
77
+ * Returns the EIP-712 browser request for a AddKeyData for signing.
78
+ *
79
+ * @param msaId MSA ID (uint64) to add the key
80
+ * @param newPublicKey 32 bytes public key to add in hex or Uint8Array
81
+ * @param expirationBlock Block number after which this payload is invalid
82
+ * @param domain
83
+ */
84
+ export declare function getEip712BrowserRequestAddKeyData(msaId: string | bigint, newPublicKey: HexString | Uint8Array, expirationBlock: number, domain?: EipDomainPayload): unknown;
85
+ /**
86
+ * Returns the EIP-712 browser request for a AddProvider for signing.
87
+ *
88
+ * @param authorizedMsaId MSA ID (uint64) that will be granted provider rights
89
+ * @param schemaIds One or more schema IDs (uint16) the provider may use
90
+ * @param expirationBlock Block number after which this payload is invalid
91
+ * @param domain
92
+ */
93
+ export declare function getEip712BrowserRequestAddProvider(authorizedMsaId: string | bigint, schemaIds: number[], expirationBlock: number, domain?: EipDomainPayload): unknown;
94
+ /**
95
+ * Returns the EIP-712 browser request for a PaginatedUpsertSignaturePayloadV2 for signing.
96
+ *
97
+ * @param schemaId uint16 schema identifier
98
+ * @param pageId uint16 page identifier
99
+ * @param targetHash uint32 page hash
100
+ * @param expiration uint32 expiration block
101
+ * @param payload HexString or Uint8Array data to upsert
102
+ * @param domain
103
+ */
104
+ export declare function getEip712BrowserRequestPaginatedUpsertSignaturePayloadV2(schemaId: number, pageId: number, targetHash: number, expiration: number, payload: HexString | Uint8Array, domain?: EipDomainPayload): unknown;
105
+ /**
106
+ * Returns the EIP-712 browser request for a PaginatedDeleteSignaturePayloadV2 for signing.
107
+ *
108
+ * @param schemaId uint16 schema identifier
109
+ * @param pageId uint16 page identifier
110
+ * @param targetHash uint32 page hash
111
+ * @param expiration uint32 expiration block
112
+ * @param domain
113
+ */
114
+ export declare function getEip712BrowserRequestPaginatedDeleteSignaturePayloadV2(schemaId: number, pageId: number, targetHash: number, expiration: number, domain?: EipDomainPayload): unknown;
115
+ /**
116
+ * Returns the EIP-712 browser request for a ItemizedSignaturePayloadV2 for signing.
117
+ *
118
+ * @param schemaId uint16 schema identifier
119
+ * @param targetHash uint32 page hash
120
+ * @param expiration uint32 expiration block
121
+ * @param actions Array of Add/Delete itemized actions
122
+ * @param domain
123
+ */
124
+ export declare function getEip712BrowserRequestItemizedSignaturePayloadV2(schemaId: number, targetHash: number, expiration: number, actions: ItemizedAction[], domain?: EipDomainPayload): unknown;
125
+ /**
126
+ * Returns the EIP-712 browser request for a ClaimHandlePayload for signing.
127
+ *
128
+ * @param handle The handle the user wishes to claim
129
+ * @param expirationBlock Block number after which this payload is invalid
130
+ * @param domain
131
+ */
132
+ export declare function getEip712BrowserRequestClaimHandlePayload(handle: string, expirationBlock: number, domain?: EipDomainPayload): unknown;
133
+ /**
134
+ * Returns the EIP-712 browser request for a PasskeyPublicKey for signing.
135
+ *
136
+ * @param publicKey The passkey’s public key (hex string or raw bytes)
137
+ * @param domain
138
+ */
139
+ export declare function getEip712BrowserRequestPasskeyPublicKey(publicKey: HexString | Uint8Array, domain?: EipDomainPayload): unknown;
@@ -0,0 +1,54 @@
1
+ import { EipDomainPayload } from './payloads';
2
+ export declare const EIP712_DOMAIN_DEFINITION: {
3
+ EIP712Domain: {
4
+ name: string;
5
+ type: string;
6
+ }[];
7
+ };
8
+ export declare const EIP712_DOMAIN_DEFAULT: EipDomainPayload;
9
+ export declare const ADD_PROVIDER_DEFINITION: {
10
+ AddProvider: {
11
+ name: string;
12
+ type: string;
13
+ }[];
14
+ };
15
+ export declare const ADD_KEY_DATA_DEFINITION: {
16
+ AddKeyData: {
17
+ name: string;
18
+ type: string;
19
+ }[];
20
+ };
21
+ export declare const CLAIM_HANDLE_PAYLOAD_DEFINITION: {
22
+ ClaimHandlePayload: {
23
+ name: string;
24
+ type: string;
25
+ }[];
26
+ };
27
+ export declare const PASSKEY_PUBLIC_KEY_DEFINITION: {
28
+ PasskeyPublicKey: {
29
+ name: string;
30
+ type: string;
31
+ }[];
32
+ };
33
+ export declare const PAGINATED_DELETE_SIGNATURE_PAYLOAD_DEFINITION_V2: {
34
+ PaginatedDeleteSignaturePayloadV2: {
35
+ name: string;
36
+ type: string;
37
+ }[];
38
+ };
39
+ export declare const PAGINATED_UPSERT_SIGNATURE_PAYLOAD_DEFINITION_V2: {
40
+ PaginatedUpsertSignaturePayloadV2: {
41
+ name: string;
42
+ type: string;
43
+ }[];
44
+ };
45
+ export declare const ITEMIZED_SIGNATURE_PAYLOAD_DEFINITION_V2: {
46
+ ItemizedSignaturePayloadV2: {
47
+ name: string;
48
+ type: string;
49
+ }[];
50
+ ItemAction: {
51
+ name: string;
52
+ type: string;
53
+ }[];
54
+ };
package/utils.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ import { HexString } from './payloads';
2
+ /**
3
+ * Validate that a number is a valid uint16 (0 to 65535)
4
+ */
5
+ export declare function isValidUint16(value: number): boolean;
6
+ /**
7
+ * Validate that a number is a valid uint32 (0 to 4294967295)
8
+ */
9
+ export declare function isValidUint32(value: number): boolean;
10
+ /**
11
+ * Validate that a number is a valid uint64 (0 to 18446744073709551615n)
12
+ */
13
+ export declare function isValidUint64String(value: bigint | string): boolean;
14
+ /**
15
+ * Validate that a string is a valid hex string
16
+ */
17
+ export declare function isHexString(value: string): value is HexString;
18
+ /**
19
+ * Universal assert function
20
+ * @param condition
21
+ * @param message
22
+ */
23
+ export declare function assert(condition: boolean, message?: string): asserts condition;