@frequency-chain/ethereum-utils 0.0.0-157820

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-157820",
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.3.1",
19
+ "@polkadot/util": "13.5.3",
20
+ "ethers": "^6.15.0"
21
+ },
22
+ "optionalDependencies": {
23
+ "@rollup/rollup-linux-x64-gnu": "^4.44.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,207 @@
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
+ export declare function createItemizedAddAction(data: HexString | Uint8Array): AddItemizedAction;
64
+ export declare function createItemizedDeleteAction(index: number): DeleteItemizedAction;
65
+ /**
66
+ * Build an ItemizedSignaturePayloadV2 for signing.
67
+ *
68
+ * @param schemaId uint16 schema identifier
69
+ * @param targetHash uint32 page hash
70
+ * @param expiration uint32 expiration block
71
+ * @param actions Array of Add/Delete itemized actions
72
+ */
73
+ export declare function createItemizedSignaturePayloadV2(schemaId: number, targetHash: number, expiration: number, actions: ItemizedAction[]): ItemizedSignaturePayloadV2;
74
+ /**
75
+ * Build a PaginatedDeleteSignaturePayloadV2 for signing.
76
+ *
77
+ * @param schemaId uint16 schema identifier
78
+ * @param pageId uint16 page identifier
79
+ * @param targetHash uint32 page hash
80
+ * @param expiration uint32 expiration block
81
+ */
82
+ export declare function createPaginatedDeleteSignaturePayloadV2(schemaId: number, pageId: number, targetHash: number, expiration: number): PaginatedDeleteSignaturePayloadV2;
83
+ /**
84
+ * Build a PaginatedUpsertSignaturePayloadV2 for signing.
85
+ *
86
+ * @param schemaId uint16 schema identifier
87
+ * @param pageId uint16 page identifier
88
+ * @param targetHash uint32 page hash
89
+ * @param expiration uint32 expiration block
90
+ * @param payload HexString or Uint8Array data to upsert
91
+ */
92
+ export declare function createPaginatedUpsertSignaturePayloadV2(schemaId: number, pageId: number, targetHash: number, expiration: number, payload: HexString | Uint8Array): PaginatedUpsertSignaturePayloadV2;
93
+ /**
94
+ * Build an SiwfSignedRequestPayload payload for signature.
95
+ *
96
+ * @param callback Callback URL for login
97
+ * @param permissions One or more schema IDs (uint16) the provider may use
98
+ * @param userIdentifierAdminUrl Only used for custom integration situations.
99
+ */
100
+ export declare function createSiwfSignedRequestPayload(callback: string, permissions: number[], userIdentifierAdminUrl?: string): SiwfSignedRequestPayload;
101
+ /**
102
+ * Build an SiwfLoginRequestPayload payload for signature.
103
+ *
104
+ * @param message login message
105
+ */
106
+ export declare function createSiwfLoginRequestPayload(message: string): SiwfLoginRequestPayload;
107
+ /**
108
+ * Returns the EIP-712 browser request for a AddKeyData for signing.
109
+ *
110
+ * @param msaId MSA ID (uint64) to add the key
111
+ * @param newPublicKey 32 bytes public key to add in hex or Uint8Array
112
+ * @param expirationBlock Block number after which this payload is invalid
113
+ * @param domain
114
+ */
115
+ export declare function getEip712BrowserRequestAddKeyData(msaId: string | bigint, newPublicKey: HexString | Uint8Array, expirationBlock: number, domain?: EipDomainPayload): unknown;
116
+ /**
117
+ * Returns the EIP-712 browser request for a AuthorizedKeyData for signing.
118
+ *
119
+ * @param msaId MSA ID (uint64) to add the key
120
+ * @param authorizedPublicKey 32 bytes public key to add in hex or Uint8Array
121
+ * @param expirationBlock Block number after which this payload is invalid
122
+ * @param domain
123
+ */
124
+ export declare function getEip712BrowserRequestAuthorizedKeyData(msaId: string | bigint, authorizedPublicKey: HexString | Uint8Array, expirationBlock: number, domain?: EipDomainPayload): unknown;
125
+ /**
126
+ * Returns the EIP-712 browser request for a AddProvider for signing.
127
+ *
128
+ * @param authorizedMsaId MSA ID (uint64) that will be granted provider rights
129
+ * @param schemaIds One or more schema IDs (uint16) the provider may use
130
+ * @param expirationBlock Block number after which this payload is invalid
131
+ * @param domain
132
+ */
133
+ export declare function getEip712BrowserRequestAddProvider(authorizedMsaId: string | bigint, schemaIds: number[], expirationBlock: number, domain?: EipDomainPayload): unknown;
134
+ /**
135
+ * Returns the EIP-712 browser request for a RecoveryCommitmentPayload for signing.
136
+ *
137
+ * @param recoveryCommitment The recovery commitment data as a Uint8Array
138
+ * @param expirationBlock Block number after which this payload is invalid
139
+ * @param domain
140
+ */
141
+ export declare function getEip712BrowserRequestRecoveryCommitmentPayload(recoveryCommitment: HexString, expirationBlock: number, domain?: EipDomainPayload): unknown;
142
+ /**
143
+ * Returns the EIP-712 browser request for a PaginatedUpsertSignaturePayloadV2 for signing.
144
+ *
145
+ * @param schemaId uint16 schema identifier
146
+ * @param pageId uint16 page identifier
147
+ * @param targetHash uint32 page hash
148
+ * @param expiration uint32 expiration block
149
+ * @param payload HexString or Uint8Array data to upsert
150
+ * @param domain
151
+ */
152
+ export declare function getEip712BrowserRequestPaginatedUpsertSignaturePayloadV2(schemaId: number, pageId: number, targetHash: number, expiration: number, payload: HexString | Uint8Array, domain?: EipDomainPayload): unknown;
153
+ /**
154
+ * Returns the EIP-712 browser request for a PaginatedDeleteSignaturePayloadV2 for signing.
155
+ *
156
+ * @param schemaId uint16 schema identifier
157
+ * @param pageId uint16 page identifier
158
+ * @param targetHash uint32 page hash
159
+ * @param expiration uint32 expiration block
160
+ * @param domain
161
+ */
162
+ export declare function getEip712BrowserRequestPaginatedDeleteSignaturePayloadV2(schemaId: number, pageId: number, targetHash: number, expiration: number, domain?: EipDomainPayload): unknown;
163
+ /**
164
+ * Returns the EIP-712 browser request for a ItemizedSignaturePayloadV2 for signing.
165
+ *
166
+ * @param schemaId uint16 schema identifier
167
+ * @param targetHash uint32 page hash
168
+ * @param expiration uint32 expiration block
169
+ * @param actions Array of Add/Delete itemized actions
170
+ * @param domain
171
+ */
172
+ export declare function getEip712BrowserRequestItemizedSignaturePayloadV2(schemaId: number, targetHash: number, expiration: number, actions: ItemizedAction[], domain?: EipDomainPayload): unknown;
173
+ /**
174
+ * Returns the EIP-712 browser request for a ClaimHandlePayload for signing.
175
+ *
176
+ * @param handle The handle the user wishes to claim
177
+ * @param expirationBlock Block number after which this payload is invalid
178
+ * @param domain
179
+ */
180
+ export declare function getEip712BrowserRequestClaimHandlePayload(handle: string, expirationBlock: number, domain?: EipDomainPayload): unknown;
181
+ /**
182
+ * Returns the EIP-712 browser request for a PasskeyPublicKey for signing.
183
+ *
184
+ * @param publicKey The passkey’s public key (hex string or raw bytes)
185
+ * @param domain
186
+ */
187
+ export declare function getEip712BrowserRequestPasskeyPublicKey(publicKey: HexString | Uint8Array, domain?: EipDomainPayload): unknown;
188
+ /**
189
+ * Returns the EIP-712 browser request for a SiwfSignedRequestPayload for signing.
190
+ *
191
+ * @param callback Callback URL for login
192
+ * @param permissions One or more schema IDs (uint16) the provider may use
193
+ * @param userIdentifierAdminUrl Only used for custom integration situations.
194
+ * @param domain
195
+ */
196
+ export declare function getEip712BrowserRequestSiwfSignedRequestPayload(callback: string, permissions: number[], userIdentifierAdminUrl?: string, domain?: EipDomainPayload): unknown;
197
+ /**
198
+ * Returns An ethereum compatible signature for the extrinsic
199
+ * @param ethereumPair
200
+ */
201
+ export declare function getEthereumRegularSigner(ethereumPair: KeyringPair): Signer;
202
+ /**
203
+ * This custom signer can get used to mimic EIP-191 message signing. By replacing the `ethereumPair.sign` with
204
+ * any wallet call we can sign any extrinsic with any wallet
205
+ * @param ethereumPair
206
+ */
207
+ 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;