@frequency-chain/ethereum-utils 0.0.0-0eb70a

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/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@frequency-chain/ethereum-utils",
3
+ "version": "0.0.0-0eb70a",
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": "^16.4.3",
19
+ "@polkadot/util": "13.5.4",
20
+ "ethers": "^6.15.0"
21
+ },
22
+ "optionalDependencies": {
23
+ "@rollup/rollup-linux-x64-gnu": "^4.46.1"
24
+ },
25
+ "module": "./esm/index.js",
26
+ "types": "index.d.ts",
27
+ "exports": {
28
+ ".": {
29
+ "types": "./index.d.ts",
30
+ "require": "./cjs/index.js",
31
+ "import": "./esm/index.js",
32
+ "default": "./esm/index.js"
33
+ }
34
+ }
35
+ }
package/payloads.d.ts ADDED
@@ -0,0 +1,104 @@
1
+ export type HexString = `0x${string}`;
2
+ export interface EcdsaSignature {
3
+ Ecdsa: HexString;
4
+ }
5
+ export interface Address20MultiAddress {
6
+ Address20: number[];
7
+ }
8
+ export type ChainType = 'Mainnet-Frequency' | 'Paseo-Testnet-Frequency' | 'Dev';
9
+ export interface AddressWrapper {
10
+ ethereumAddress: HexString;
11
+ unifiedAddress: HexString;
12
+ unifiedAddressSS58: string;
13
+ }
14
+ export interface EthereumKeyPair {
15
+ privateKey: HexString;
16
+ publicKey: HexString;
17
+ address: AddressWrapper;
18
+ mnemonic: string;
19
+ }
20
+ export interface PaginatedUpsertSignaturePayloadV2 {
21
+ type: 'PaginatedUpsertSignaturePayloadV2';
22
+ schemaId: number;
23
+ pageId: number;
24
+ targetHash: number;
25
+ expiration: number;
26
+ payload: HexString;
27
+ }
28
+ export interface PaginatedDeleteSignaturePayloadV2 {
29
+ type: 'PaginatedDeleteSignaturePayloadV2';
30
+ schemaId: number;
31
+ pageId: number;
32
+ targetHash: number;
33
+ expiration: number;
34
+ }
35
+ export interface AddItemizedAction {
36
+ actionType: 'Add';
37
+ data: HexString;
38
+ index: 0;
39
+ }
40
+ export interface DeleteItemizedAction {
41
+ actionType: 'Delete';
42
+ data: '0x';
43
+ index: number;
44
+ }
45
+ export type ItemizedAction = AddItemizedAction | DeleteItemizedAction;
46
+ export interface ItemizedSignaturePayloadV2 {
47
+ type: 'ItemizedSignaturePayloadV2';
48
+ schemaId: number;
49
+ targetHash: number;
50
+ expiration: number;
51
+ actions: ItemizedAction[];
52
+ }
53
+ export interface PasskeyPublicKey {
54
+ type: 'PasskeyPublicKey';
55
+ publicKey: HexString;
56
+ }
57
+ export interface ClaimHandlePayload {
58
+ type: 'ClaimHandlePayload';
59
+ handle: string;
60
+ expiration: number;
61
+ }
62
+ export interface AddKeyData {
63
+ type: 'AddKeyData';
64
+ msaId: string;
65
+ expiration: number;
66
+ newPublicKey: HexString;
67
+ }
68
+ export interface AuthorizedKeyData {
69
+ type: 'AuthorizedKeyData';
70
+ msaId: string;
71
+ expiration: number;
72
+ authorizedPublicKey: HexString;
73
+ }
74
+ export interface AddProvider {
75
+ type: 'AddProvider';
76
+ authorizedMsaId: string;
77
+ schemaIds: number[];
78
+ expiration: number;
79
+ }
80
+ export interface RecoveryCommitmentPayload {
81
+ type: 'RecoveryCommitmentPayload';
82
+ recoveryCommitment: HexString;
83
+ expiration: number;
84
+ }
85
+ export interface SiwfSignedRequestPayload {
86
+ type: 'SiwfSignedRequestPayload';
87
+ callback: string;
88
+ permissions: number[];
89
+ userIdentifierAdminUrl?: string;
90
+ }
91
+ export interface SiwfLoginRequestPayload {
92
+ type: 'SiwfLoginRequestPayload';
93
+ message: string;
94
+ }
95
+ export type SupportedPayload = PaginatedUpsertSignaturePayloadV2 | PaginatedDeleteSignaturePayloadV2 | ItemizedSignaturePayloadV2 | PasskeyPublicKey | ClaimHandlePayload | AddKeyData | AuthorizedKeyData | AddProvider | RecoveryCommitmentPayload | SiwfSignedRequestPayload | SiwfLoginRequestPayload;
96
+ export type NormalizedSupportedPayload = Omit<SupportedPayload, 'type'>;
97
+ export interface EipDomainPayload {
98
+ name: string;
99
+ version: string;
100
+ chainId: HexString;
101
+ verifyingContract: HexString;
102
+ }
103
+ export type SupportedPayloadTypes = SupportedPayload['type'];
104
+ export type SignatureType = 'EIP-712' | 'EIP-191';
package/signature.d.ts ADDED
@@ -0,0 +1,217 @@
1
+ import { AddKeyData, AuthorizedKeyData, AddProvider, ChainType, ClaimHandlePayload, EcdsaSignature, ItemizedSignaturePayloadV2, PaginatedDeleteSignaturePayloadV2, PaginatedUpsertSignaturePayloadV2, PasskeyPublicKey, SupportedPayload, HexString, AddItemizedAction, DeleteItemizedAction, ItemizedAction, EipDomainPayload, RecoveryCommitmentPayload, SiwfSignedRequestPayload, SiwfLoginRequestPayload } from './payloads.js';
2
+ import { KeyringPair } from '@polkadot/keyring/types';
3
+ import { Signer } from '@polkadot/types/types';
4
+ /**
5
+ * Signing EIP-712 or ERC-191 compatible signature based on payload
6
+ * @param secretKey
7
+ * @param payload
8
+ * @param chain
9
+ */
10
+ export declare function sign(secretKey: HexString, payload: SupportedPayload, chain: ChainType): Promise<EcdsaSignature>;
11
+ /**
12
+ * Verify EIP-712 and ERC-191 signatures based on payload
13
+ * @param ethereumAddress
14
+ * @param signature
15
+ * @param payload
16
+ * @param chain
17
+ */
18
+ export declare function verifySignature(ethereumAddress: HexString, signature: HexString, payload: SupportedPayload, chain: ChainType): boolean;
19
+ /**
20
+ * Build an AddKeyData payload for signature.
21
+ *
22
+ * @param msaId MSA ID (uint64) to add the key
23
+ * @param newPublicKey 32 bytes public key to add in hex or Uint8Array
24
+ * @param expirationBlock Block number after which this payload is invalid
25
+ */
26
+ export declare function createAddKeyData(msaId: string | bigint, newPublicKey: HexString | Uint8Array, expirationBlock: number): AddKeyData;
27
+ /**
28
+ * Build an AuthorizedKeyData payload for signature.
29
+ *
30
+ * @param msaId MSA ID (uint64) to add the key
31
+ * @param authorizedPublicKey 32 bytes public key to authorize in hex or Uint8Array
32
+ * @param expirationBlock Block number after which this payload is invalid
33
+ */
34
+ export declare function createAuthorizedKeyData(msaId: string | bigint, newPublicKey: HexString | Uint8Array, expirationBlock: number): AuthorizedKeyData;
35
+ /**
36
+ * Build an AddProvider payload for signature.
37
+ *
38
+ * @param authorizedMsaId MSA ID (uint64) that will be granted provider rights
39
+ * @param schemaIds One or more schema IDs (uint16) the provider may use
40
+ * @param expirationBlock Block number after which this payload is invalid
41
+ */
42
+ export declare function createAddProvider(authorizedMsaId: string | bigint, schemaIds: number[], expirationBlock: number): AddProvider;
43
+ /**
44
+ * Build a RecoveryCommitmentPayload for signature.
45
+ *
46
+ * @param recoveryCommitment The recovery commitment data as a HexString
47
+ * @param expirationBlock Block number after which this payload is invalid
48
+ */
49
+ export declare function createRecoveryCommitmentPayload(recoveryCommitment: HexString, expirationBlock: number): RecoveryCommitmentPayload;
50
+ /**
51
+ * Build a ClaimHandlePayload for signature.
52
+ *
53
+ * @param handle The handle the user wishes to claim
54
+ * @param expirationBlock Block number after which this payload is invalid
55
+ */
56
+ export declare function createClaimHandlePayload(handle: string, expirationBlock: number): ClaimHandlePayload;
57
+ /**
58
+ * Build a PasskeyPublicKey payload for signature.
59
+ *
60
+ * @param publicKey The passkey’s public key (hex string or raw bytes)
61
+ */
62
+ export declare function createPasskeyPublicKey(publicKey: HexString | Uint8Array): PasskeyPublicKey;
63
+ /**
64
+ * Build AddAction payload for Itemized storage.
65
+ *
66
+ * @param data The data to be persisted on the Frequency chain
67
+ */
68
+ export declare function createItemizedAddAction(data: HexString | Uint8Array): AddItemizedAction;
69
+ /**
70
+ * Build DeleteAction payload for Itemized storage.
71
+ *
72
+ * @param index The index of the item that we want to remove from the Frequency chain
73
+ */
74
+ export declare function createItemizedDeleteAction(index: number): DeleteItemizedAction;
75
+ /**
76
+ * Build an ItemizedSignaturePayloadV2 for signing.
77
+ *
78
+ * @param schemaId uint16 schema identifier
79
+ * @param targetHash uint32 page hash
80
+ * @param expiration uint32 expiration block
81
+ * @param actions Array of Add/Delete itemized actions
82
+ */
83
+ export declare function createItemizedSignaturePayloadV2(schemaId: number, targetHash: number, expiration: number, actions: ItemizedAction[]): ItemizedSignaturePayloadV2;
84
+ /**
85
+ * Build a PaginatedDeleteSignaturePayloadV2 for signing.
86
+ *
87
+ * @param schemaId uint16 schema identifier
88
+ * @param pageId uint16 page identifier
89
+ * @param targetHash uint32 page hash
90
+ * @param expiration uint32 expiration block
91
+ */
92
+ export declare function createPaginatedDeleteSignaturePayloadV2(schemaId: number, pageId: number, targetHash: number, expiration: number): PaginatedDeleteSignaturePayloadV2;
93
+ /**
94
+ * Build a PaginatedUpsertSignaturePayloadV2 for signing.
95
+ *
96
+ * @param schemaId uint16 schema identifier
97
+ * @param pageId uint16 page identifier
98
+ * @param targetHash uint32 page hash
99
+ * @param expiration uint32 expiration block
100
+ * @param payload HexString or Uint8Array data to upsert
101
+ */
102
+ export declare function createPaginatedUpsertSignaturePayloadV2(schemaId: number, pageId: number, targetHash: number, expiration: number, payload: HexString | Uint8Array): PaginatedUpsertSignaturePayloadV2;
103
+ /**
104
+ * Build an SiwfSignedRequestPayload payload for signature.
105
+ *
106
+ * @param callback Callback URL for login
107
+ * @param permissions One or more schema IDs (uint16) the provider may use
108
+ * @param userIdentifierAdminUrl Only used for custom integration situations.
109
+ */
110
+ export declare function createSiwfSignedRequestPayload(callback: string, permissions: number[], userIdentifierAdminUrl?: string): SiwfSignedRequestPayload;
111
+ /**
112
+ * Build an SiwfLoginRequestPayload payload for signature.
113
+ *
114
+ * @param message login message
115
+ */
116
+ export declare function createSiwfLoginRequestPayload(message: string): SiwfLoginRequestPayload;
117
+ /**
118
+ * Returns the EIP-712 browser request for a AddKeyData for signing.
119
+ *
120
+ * @param msaId MSA ID (uint64) to add the key
121
+ * @param newPublicKey 32 bytes public key to add in hex or Uint8Array
122
+ * @param expirationBlock Block number after which this payload is invalid
123
+ * @param domain
124
+ */
125
+ export declare function getEip712BrowserRequestAddKeyData(msaId: string | bigint, newPublicKey: HexString | Uint8Array, expirationBlock: number, domain?: EipDomainPayload): unknown;
126
+ /**
127
+ * Returns the EIP-712 browser request for a AuthorizedKeyData for signing.
128
+ *
129
+ * @param msaId MSA ID (uint64) to add the key
130
+ * @param authorizedPublicKey 32 bytes public key to add in hex or Uint8Array
131
+ * @param expirationBlock Block number after which this payload is invalid
132
+ * @param domain
133
+ */
134
+ export declare function getEip712BrowserRequestAuthorizedKeyData(msaId: string | bigint, authorizedPublicKey: HexString | Uint8Array, expirationBlock: number, domain?: EipDomainPayload): unknown;
135
+ /**
136
+ * Returns the EIP-712 browser request for a AddProvider for signing.
137
+ *
138
+ * @param authorizedMsaId MSA ID (uint64) that will be granted provider rights
139
+ * @param schemaIds One or more schema IDs (uint16) the provider may use
140
+ * @param expirationBlock Block number after which this payload is invalid
141
+ * @param domain
142
+ */
143
+ export declare function getEip712BrowserRequestAddProvider(authorizedMsaId: string | bigint, schemaIds: number[], expirationBlock: number, domain?: EipDomainPayload): unknown;
144
+ /**
145
+ * Returns the EIP-712 browser request for a RecoveryCommitmentPayload for signing.
146
+ *
147
+ * @param recoveryCommitment The recovery commitment data as a Uint8Array
148
+ * @param expirationBlock Block number after which this payload is invalid
149
+ * @param domain
150
+ */
151
+ export declare function getEip712BrowserRequestRecoveryCommitmentPayload(recoveryCommitment: HexString, expirationBlock: number, domain?: EipDomainPayload): unknown;
152
+ /**
153
+ * Returns the EIP-712 browser request for a PaginatedUpsertSignaturePayloadV2 for signing.
154
+ *
155
+ * @param schemaId uint16 schema identifier
156
+ * @param pageId uint16 page identifier
157
+ * @param targetHash uint32 page hash
158
+ * @param expiration uint32 expiration block
159
+ * @param payload HexString or Uint8Array data to upsert
160
+ * @param domain
161
+ */
162
+ export declare function getEip712BrowserRequestPaginatedUpsertSignaturePayloadV2(schemaId: number, pageId: number, targetHash: number, expiration: number, payload: HexString | Uint8Array, domain?: EipDomainPayload): unknown;
163
+ /**
164
+ * Returns the EIP-712 browser request for a PaginatedDeleteSignaturePayloadV2 for signing.
165
+ *
166
+ * @param schemaId uint16 schema identifier
167
+ * @param pageId uint16 page identifier
168
+ * @param targetHash uint32 page hash
169
+ * @param expiration uint32 expiration block
170
+ * @param domain
171
+ */
172
+ export declare function getEip712BrowserRequestPaginatedDeleteSignaturePayloadV2(schemaId: number, pageId: number, targetHash: number, expiration: number, domain?: EipDomainPayload): unknown;
173
+ /**
174
+ * Returns the EIP-712 browser request for a ItemizedSignaturePayloadV2 for signing.
175
+ *
176
+ * @param schemaId uint16 schema identifier
177
+ * @param targetHash uint32 page hash
178
+ * @param expiration uint32 expiration block
179
+ * @param actions Array of Add/Delete itemized actions
180
+ * @param domain
181
+ */
182
+ export declare function getEip712BrowserRequestItemizedSignaturePayloadV2(schemaId: number, targetHash: number, expiration: number, actions: ItemizedAction[], domain?: EipDomainPayload): unknown;
183
+ /**
184
+ * Returns the EIP-712 browser request for a ClaimHandlePayload for signing.
185
+ *
186
+ * @param handle The handle the user wishes to claim
187
+ * @param expirationBlock Block number after which this payload is invalid
188
+ * @param domain
189
+ */
190
+ export declare function getEip712BrowserRequestClaimHandlePayload(handle: string, expirationBlock: number, domain?: EipDomainPayload): unknown;
191
+ /**
192
+ * Returns the EIP-712 browser request for a PasskeyPublicKey for signing.
193
+ *
194
+ * @param publicKey The passkey’s public key (hex string or raw bytes)
195
+ * @param domain
196
+ */
197
+ export declare function getEip712BrowserRequestPasskeyPublicKey(publicKey: HexString | Uint8Array, domain?: EipDomainPayload): unknown;
198
+ /**
199
+ * Returns the EIP-712 browser request for a SiwfSignedRequestPayload for signing.
200
+ *
201
+ * @param callback Callback URL for login
202
+ * @param permissions One or more schema IDs (uint16) the provider may use
203
+ * @param userIdentifierAdminUrl Only used for custom integration situations.
204
+ * @param domain
205
+ */
206
+ export declare function getEip712BrowserRequestSiwfSignedRequestPayload(callback: string, permissions: number[], userIdentifierAdminUrl?: string, domain?: EipDomainPayload): unknown;
207
+ /**
208
+ * Returns An ethereum compatible signature for the extrinsic
209
+ * @param ethereumPair
210
+ */
211
+ export declare function getEthereumRegularSigner(ethereumPair: KeyringPair): Signer;
212
+ /**
213
+ * This custom signer can get used to mimic EIP-191 message signing. By replacing the `ethereumPair.sign` with
214
+ * any wallet call we can sign any extrinsic with any wallet
215
+ * @param ethereumPair
216
+ */
217
+ export declare function getEthereumMessageSigner(ethereumPair: KeyringPair): Signer;
@@ -0,0 +1,130 @@
1
+ import { EipDomainPayload } from './payloads.js';
2
+ export declare const EIP712_DOMAIN_DEFINITION: {
3
+ EIP712Domain: {
4
+ name: string;
5
+ type: string;
6
+ }[];
7
+ };
8
+ export declare const EIP712_DOMAIN_MAINNET: EipDomainPayload;
9
+ export declare const EIP712_DOMAIN_TESTNET: EipDomainPayload;
10
+ export declare const ADD_PROVIDER_DEFINITION: {
11
+ AddProvider: {
12
+ name: string;
13
+ type: string;
14
+ }[];
15
+ };
16
+ export declare const ADD_KEY_DATA_DEFINITION: {
17
+ AddKeyData: {
18
+ name: string;
19
+ type: string;
20
+ }[];
21
+ };
22
+ export declare const AUTHORIZED_KEY_DATA_DEFINITION: {
23
+ AuthorizedKeyData: {
24
+ name: string;
25
+ type: string;
26
+ }[];
27
+ };
28
+ export declare const RECOVERY_COMMITMENT_PAYLOAD_DEFINITION: {
29
+ RecoveryCommitmentPayload: {
30
+ name: string;
31
+ type: string;
32
+ }[];
33
+ };
34
+ export declare const CLAIM_HANDLE_PAYLOAD_DEFINITION: {
35
+ ClaimHandlePayload: {
36
+ name: string;
37
+ type: string;
38
+ }[];
39
+ };
40
+ export declare const PASSKEY_PUBLIC_KEY_DEFINITION: {
41
+ PasskeyPublicKey: {
42
+ name: string;
43
+ type: string;
44
+ }[];
45
+ };
46
+ export declare const PAGINATED_DELETE_SIGNATURE_PAYLOAD_DEFINITION_V2: {
47
+ PaginatedDeleteSignaturePayloadV2: {
48
+ name: string;
49
+ type: string;
50
+ }[];
51
+ };
52
+ export declare const PAGINATED_UPSERT_SIGNATURE_PAYLOAD_DEFINITION_V2: {
53
+ PaginatedUpsertSignaturePayloadV2: {
54
+ name: string;
55
+ type: string;
56
+ }[];
57
+ };
58
+ export declare const ITEMIZED_SIGNATURE_PAYLOAD_DEFINITION_V2: {
59
+ ItemizedSignaturePayloadV2: {
60
+ name: string;
61
+ type: string;
62
+ }[];
63
+ ItemAction: {
64
+ name: string;
65
+ type: string;
66
+ }[];
67
+ };
68
+ export declare const SIWF_SIGNED_REQUEST_PAYLOAD_DEFINITION: {
69
+ SiwfSignedRequestPayload: {
70
+ name: string;
71
+ type: string;
72
+ }[];
73
+ };
74
+ declare const PAYLOAD_DEFINITIONS: ({
75
+ AddProvider: {
76
+ name: string;
77
+ type: string;
78
+ }[];
79
+ } | {
80
+ AddKeyData: {
81
+ name: string;
82
+ type: string;
83
+ }[];
84
+ } | {
85
+ AuthorizedKeyData: {
86
+ name: string;
87
+ type: string;
88
+ }[];
89
+ } | {
90
+ RecoveryCommitmentPayload: {
91
+ name: string;
92
+ type: string;
93
+ }[];
94
+ } | {
95
+ ClaimHandlePayload: {
96
+ name: string;
97
+ type: string;
98
+ }[];
99
+ } | {
100
+ PasskeyPublicKey: {
101
+ name: string;
102
+ type: string;
103
+ }[];
104
+ } | {
105
+ PaginatedDeleteSignaturePayloadV2: {
106
+ name: string;
107
+ type: string;
108
+ }[];
109
+ } | {
110
+ PaginatedUpsertSignaturePayloadV2: {
111
+ name: string;
112
+ type: string;
113
+ }[];
114
+ } | {
115
+ ItemizedSignaturePayloadV2: {
116
+ name: string;
117
+ type: string;
118
+ }[];
119
+ ItemAction: {
120
+ name: string;
121
+ type: string;
122
+ }[];
123
+ } | {
124
+ SiwfSignedRequestPayload: {
125
+ name: string;
126
+ type: string;
127
+ }[];
128
+ })[];
129
+ export type SupportedPayloadDefinitions = (typeof PAYLOAD_DEFINITIONS)[number];
130
+ export {};
package/utils.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ import { HexString } from './payloads.js';
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;