@frequency-chain/ethereum-utils 1.17.0-rc5 → 1.17.0-rc7
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/address.d.ts +1 -1
- package/browser/frequency-ethereum-utils.esm.min.js +902 -656
- package/browser/frequency-ethereum-utils.umd.min.js +882 -644
- package/cjs/index.js +8 -8
- package/cjs/signature.definitions.js +53 -3
- package/cjs/signature.js +184 -64
- package/esm/index.js +8 -8
- package/esm/signature.definitions.js +52 -2
- package/esm/signature.js +137 -22
- package/index.d.ts +33 -15
- package/package.json +7 -4
- package/payloads.d.ts +20 -1
- package/signature.d.ts +45 -5
- package/signature.definitions.d.ts +67 -2
- package/utils.d.ts +1 -1
package/esm/signature.js
CHANGED
|
@@ -1,36 +1,54 @@
|
|
|
1
|
-
import { assert, isHexString, isValidUint16, isValidUint32, isValidUint64String } from './utils';
|
|
2
|
-
import { reverseUnifiedAddressToEthereumAddress } from './address';
|
|
1
|
+
import { assert, isHexString, isValidUint16, isValidUint32, isValidUint64String } from './utils.js';
|
|
2
|
+
import { reverseUnifiedAddressToEthereumAddress } from './address.js';
|
|
3
3
|
import { ethers } from 'ethers';
|
|
4
4
|
import { u8aToHex } from '@polkadot/util';
|
|
5
|
-
import { ADD_KEY_DATA_DEFINITION, ADD_PROVIDER_DEFINITION, CLAIM_HANDLE_PAYLOAD_DEFINITION,
|
|
5
|
+
import { ADD_KEY_DATA_DEFINITION, ADD_PROVIDER_DEFINITION, AUTHORIZED_KEY_DATA_DEFINITION, CLAIM_HANDLE_PAYLOAD_DEFINITION, EIP712_DOMAIN_MAINNET, EIP712_DOMAIN_DEFINITION, ITEMIZED_SIGNATURE_PAYLOAD_DEFINITION_V2, PAGINATED_DELETE_SIGNATURE_PAYLOAD_DEFINITION_V2, PAGINATED_UPSERT_SIGNATURE_PAYLOAD_DEFINITION_V2, PASSKEY_PUBLIC_KEY_DEFINITION, SIWF_SIGNED_REQUEST_PAYLOAD_DEFINITION, EIP712_DOMAIN_TESTNET, } from './signature.definitions.js';
|
|
6
6
|
/**
|
|
7
|
-
* Signing EIP-712 compatible signature
|
|
7
|
+
* Signing EIP-712 or ERC-191 compatible signature based on payload
|
|
8
8
|
* @param secretKey
|
|
9
9
|
* @param payload
|
|
10
10
|
* @param chain
|
|
11
11
|
*/
|
|
12
|
-
export async function
|
|
13
|
-
const
|
|
12
|
+
export async function sign(secretKey, payload, chain) {
|
|
13
|
+
const signatureType = getSignatureType(payload.type);
|
|
14
14
|
const normalizedPayload = normalizePayload(payload);
|
|
15
15
|
const wallet = new ethers.Wallet(secretKey);
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
let signature;
|
|
17
|
+
switch (signatureType) {
|
|
18
|
+
case 'EIP-712':
|
|
19
|
+
// TODO: use correct contract address for different payloads
|
|
20
|
+
signature = await wallet.signTypedData(chain === 'Mainnet-Frequency' ? EIP712_DOMAIN_MAINNET : EIP712_DOMAIN_TESTNET, getTypesFor(payload.type), normalizedPayload);
|
|
21
|
+
break;
|
|
22
|
+
case 'EIP-191':
|
|
23
|
+
signature = await wallet.signMessage(payload.message);
|
|
24
|
+
break;
|
|
25
|
+
default:
|
|
26
|
+
throw new Error(`Unsupported signature type : ${signatureType}`);
|
|
27
|
+
}
|
|
19
28
|
return { Ecdsa: signature };
|
|
20
29
|
}
|
|
21
30
|
/**
|
|
22
|
-
* Verify EIP-712 signatures
|
|
31
|
+
* Verify EIP-712 and ERC-191 signatures based on payload
|
|
23
32
|
* @param ethereumAddress
|
|
24
33
|
* @param signature
|
|
25
34
|
* @param payload
|
|
26
35
|
* @param chain
|
|
27
36
|
*/
|
|
28
|
-
export function
|
|
29
|
-
const
|
|
37
|
+
export function verifySignature(ethereumAddress, signature, payload, chain) {
|
|
38
|
+
const signatureType = getSignatureType(payload.type);
|
|
30
39
|
const normalizedPayload = normalizePayload(payload);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
40
|
+
let recoveredAddress;
|
|
41
|
+
switch (signatureType) {
|
|
42
|
+
case 'EIP-712':
|
|
43
|
+
// TODO: use correct contract address for different payloads
|
|
44
|
+
recoveredAddress = ethers.verifyTypedData(chain === 'Mainnet-Frequency' ? EIP712_DOMAIN_MAINNET : EIP712_DOMAIN_TESTNET, getTypesFor(payload.type), normalizedPayload, signature);
|
|
45
|
+
break;
|
|
46
|
+
case 'EIP-191':
|
|
47
|
+
recoveredAddress = ethers.verifyMessage(payload.message, signature);
|
|
48
|
+
break;
|
|
49
|
+
default:
|
|
50
|
+
throw new Error(`Unsupported signature type : ${signatureType}`);
|
|
51
|
+
}
|
|
34
52
|
return recoveredAddress.toLowerCase() === ethereumAddress.toLowerCase();
|
|
35
53
|
}
|
|
36
54
|
function normalizePayload(payload) {
|
|
@@ -42,6 +60,7 @@ function normalizePayload(payload) {
|
|
|
42
60
|
case 'PasskeyPublicKey':
|
|
43
61
|
case 'ClaimHandlePayload':
|
|
44
62
|
case 'AddProvider':
|
|
63
|
+
case 'SiwfLoginRequestPayload':
|
|
45
64
|
break;
|
|
46
65
|
case 'AddKeyData':
|
|
47
66
|
// convert to 20 bytes ethereum address for signature
|
|
@@ -50,6 +69,18 @@ function normalizePayload(payload) {
|
|
|
50
69
|
}
|
|
51
70
|
clonedPayload.newPublicKey = clonedPayload.newPublicKey.toLowerCase();
|
|
52
71
|
break;
|
|
72
|
+
case 'AuthorizedKeyData':
|
|
73
|
+
// convert to 20 bytes ethereum address for signature
|
|
74
|
+
if (clonedPayload.authorizedPublicKey.length !== 42) {
|
|
75
|
+
clonedPayload.authorizedPublicKey = reverseUnifiedAddressToEthereumAddress(payload.authorizedPublicKey);
|
|
76
|
+
}
|
|
77
|
+
clonedPayload.authorizedPublicKey = clonedPayload.authorizedPublicKey.toLowerCase();
|
|
78
|
+
break;
|
|
79
|
+
case 'SiwfSignedRequestPayload':
|
|
80
|
+
if (clonedPayload.userIdentifierAdminUrl == null) {
|
|
81
|
+
clonedPayload.userIdentifierAdminUrl = '';
|
|
82
|
+
}
|
|
83
|
+
break;
|
|
53
84
|
default:
|
|
54
85
|
throw new Error(`Unsupported payload type: ${JSON.stringify(payload)}`);
|
|
55
86
|
}
|
|
@@ -65,7 +96,10 @@ function getTypesFor(payloadType) {
|
|
|
65
96
|
PasskeyPublicKey: PASSKEY_PUBLIC_KEY_DEFINITION,
|
|
66
97
|
ClaimHandlePayload: CLAIM_HANDLE_PAYLOAD_DEFINITION,
|
|
67
98
|
AddKeyData: ADD_KEY_DATA_DEFINITION,
|
|
99
|
+
AuthorizedKeyData: AUTHORIZED_KEY_DATA_DEFINITION,
|
|
68
100
|
AddProvider: ADD_PROVIDER_DEFINITION,
|
|
101
|
+
// offchain signatures
|
|
102
|
+
SiwfSignedRequestPayload: SIWF_SIGNED_REQUEST_PAYLOAD_DEFINITION,
|
|
69
103
|
};
|
|
70
104
|
const definition = PAYLOAD_TYPE_DEFINITIONS[payloadType];
|
|
71
105
|
if (!definition) {
|
|
@@ -73,6 +107,12 @@ function getTypesFor(payloadType) {
|
|
|
73
107
|
}
|
|
74
108
|
return definition;
|
|
75
109
|
}
|
|
110
|
+
function getSignatureType(payloadType) {
|
|
111
|
+
if (payloadType === 'SiwfLoginRequestPayload') {
|
|
112
|
+
return 'EIP-191';
|
|
113
|
+
}
|
|
114
|
+
return 'EIP-712';
|
|
115
|
+
}
|
|
76
116
|
/**
|
|
77
117
|
* Build an AddKeyData payload for signature.
|
|
78
118
|
*
|
|
@@ -93,6 +133,26 @@ export function createAddKeyData(msaId, newPublicKey, expirationBlock) {
|
|
|
93
133
|
newPublicKey: parsedNewPublicKey,
|
|
94
134
|
};
|
|
95
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Build an AuthorizedKeyData payload for signature.
|
|
138
|
+
*
|
|
139
|
+
* @param msaId MSA ID (uint64) to add the key
|
|
140
|
+
* @param authorizedPublicKey 32 bytes public key to authorize in hex or Uint8Array
|
|
141
|
+
* @param expirationBlock Block number after which this payload is invalid
|
|
142
|
+
*/
|
|
143
|
+
export function createAuthorizedKeyData(msaId, newPublicKey, expirationBlock) {
|
|
144
|
+
const parsedMsaId = typeof msaId === 'string' ? msaId : `${msaId}`;
|
|
145
|
+
const parsedNewPublicKey = typeof newPublicKey === 'object' ? u8aToHex(newPublicKey) : newPublicKey;
|
|
146
|
+
assert(isValidUint64String(parsedMsaId), 'msaId should be a valid uint64');
|
|
147
|
+
assert(isValidUint32(expirationBlock), 'expiration should be a valid uint32');
|
|
148
|
+
assert(isHexString(parsedNewPublicKey), 'newPublicKey should be valid hex');
|
|
149
|
+
return {
|
|
150
|
+
type: 'AuthorizedKeyData',
|
|
151
|
+
msaId: parsedMsaId,
|
|
152
|
+
expiration: expirationBlock,
|
|
153
|
+
authorizedPublicKey: parsedNewPublicKey,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
96
156
|
/**
|
|
97
157
|
* Build an AddProvider payload for signature.
|
|
98
158
|
*
|
|
@@ -217,6 +277,35 @@ export function createPaginatedUpsertSignaturePayloadV2(schemaId, pageId, target
|
|
|
217
277
|
payload: parsedPayload,
|
|
218
278
|
};
|
|
219
279
|
}
|
|
280
|
+
/**
|
|
281
|
+
* Build an SiwfSignedRequestPayload payload for signature.
|
|
282
|
+
*
|
|
283
|
+
* @param callback Callback URL for login
|
|
284
|
+
* @param permissions One or more schema IDs (uint16) the provider may use
|
|
285
|
+
* @param userIdentifierAdminUrl Only used for custom integration situations.
|
|
286
|
+
*/
|
|
287
|
+
export function createSiwfSignedRequestPayload(callback, permissions, userIdentifierAdminUrl) {
|
|
288
|
+
permissions.forEach((schemaId) => {
|
|
289
|
+
assert(isValidUint16(schemaId), 'permission should be a valid uint16');
|
|
290
|
+
});
|
|
291
|
+
return {
|
|
292
|
+
type: 'SiwfSignedRequestPayload',
|
|
293
|
+
callback: callback,
|
|
294
|
+
permissions,
|
|
295
|
+
userIdentifierAdminUrl,
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Build an SiwfLoginRequestPayload payload for signature.
|
|
300
|
+
*
|
|
301
|
+
* @param message login message
|
|
302
|
+
*/
|
|
303
|
+
export function createSiwfLoginRequestPayload(message) {
|
|
304
|
+
return {
|
|
305
|
+
type: 'SiwfLoginRequestPayload',
|
|
306
|
+
message,
|
|
307
|
+
};
|
|
308
|
+
}
|
|
220
309
|
/**
|
|
221
310
|
* Returns the EIP-712 browser request for a AddKeyData for signing.
|
|
222
311
|
*
|
|
@@ -225,11 +314,24 @@ export function createPaginatedUpsertSignaturePayloadV2(schemaId, pageId, target
|
|
|
225
314
|
* @param expirationBlock Block number after which this payload is invalid
|
|
226
315
|
* @param domain
|
|
227
316
|
*/
|
|
228
|
-
export function getEip712BrowserRequestAddKeyData(msaId, newPublicKey, expirationBlock, domain =
|
|
317
|
+
export function getEip712BrowserRequestAddKeyData(msaId, newPublicKey, expirationBlock, domain = EIP712_DOMAIN_MAINNET) {
|
|
229
318
|
const message = createAddKeyData(msaId, newPublicKey, expirationBlock);
|
|
230
319
|
const normalized = normalizePayload(message);
|
|
231
320
|
return createEip712Payload(ADD_KEY_DATA_DEFINITION, message.type, domain, normalized);
|
|
232
321
|
}
|
|
322
|
+
/**
|
|
323
|
+
* Returns the EIP-712 browser request for a AuthorizedKeyData for signing.
|
|
324
|
+
*
|
|
325
|
+
* @param msaId MSA ID (uint64) to add the key
|
|
326
|
+
* @param authorizedPublicKey 32 bytes public key to add in hex or Uint8Array
|
|
327
|
+
* @param expirationBlock Block number after which this payload is invalid
|
|
328
|
+
* @param domain
|
|
329
|
+
*/
|
|
330
|
+
export function getEip712BrowserRequestAuthorizedKeyData(msaId, authorizedPublicKey, expirationBlock, domain = EIP712_DOMAIN_MAINNET) {
|
|
331
|
+
const message = createAuthorizedKeyData(msaId, authorizedPublicKey, expirationBlock);
|
|
332
|
+
const normalized = normalizePayload(message);
|
|
333
|
+
return createEip712Payload(AUTHORIZED_KEY_DATA_DEFINITION, message.type, domain, normalized);
|
|
334
|
+
}
|
|
233
335
|
/**
|
|
234
336
|
* Returns the EIP-712 browser request for a AddProvider for signing.
|
|
235
337
|
*
|
|
@@ -238,7 +340,7 @@ export function getEip712BrowserRequestAddKeyData(msaId, newPublicKey, expiratio
|
|
|
238
340
|
* @param expirationBlock Block number after which this payload is invalid
|
|
239
341
|
* @param domain
|
|
240
342
|
*/
|
|
241
|
-
export function getEip712BrowserRequestAddProvider(authorizedMsaId, schemaIds, expirationBlock, domain =
|
|
343
|
+
export function getEip712BrowserRequestAddProvider(authorizedMsaId, schemaIds, expirationBlock, domain = EIP712_DOMAIN_MAINNET) {
|
|
242
344
|
const message = createAddProvider(authorizedMsaId, schemaIds, expirationBlock);
|
|
243
345
|
const normalized = normalizePayload(message);
|
|
244
346
|
return createEip712Payload(ADD_PROVIDER_DEFINITION, message.type, domain, normalized);
|
|
@@ -253,7 +355,7 @@ export function getEip712BrowserRequestAddProvider(authorizedMsaId, schemaIds, e
|
|
|
253
355
|
* @param payload HexString or Uint8Array data to upsert
|
|
254
356
|
* @param domain
|
|
255
357
|
*/
|
|
256
|
-
export function getEip712BrowserRequestPaginatedUpsertSignaturePayloadV2(schemaId, pageId, targetHash, expiration, payload, domain =
|
|
358
|
+
export function getEip712BrowserRequestPaginatedUpsertSignaturePayloadV2(schemaId, pageId, targetHash, expiration, payload, domain = EIP712_DOMAIN_MAINNET) {
|
|
257
359
|
const message = createPaginatedUpsertSignaturePayloadV2(schemaId, pageId, targetHash, expiration, payload);
|
|
258
360
|
const normalized = normalizePayload(message);
|
|
259
361
|
return createEip712Payload(PAGINATED_UPSERT_SIGNATURE_PAYLOAD_DEFINITION_V2, message.type, domain, normalized);
|
|
@@ -267,7 +369,7 @@ export function getEip712BrowserRequestPaginatedUpsertSignaturePayloadV2(schemaI
|
|
|
267
369
|
* @param expiration uint32 expiration block
|
|
268
370
|
* @param domain
|
|
269
371
|
*/
|
|
270
|
-
export function getEip712BrowserRequestPaginatedDeleteSignaturePayloadV2(schemaId, pageId, targetHash, expiration, domain =
|
|
372
|
+
export function getEip712BrowserRequestPaginatedDeleteSignaturePayloadV2(schemaId, pageId, targetHash, expiration, domain = EIP712_DOMAIN_MAINNET) {
|
|
271
373
|
const message = createPaginatedDeleteSignaturePayloadV2(schemaId, pageId, targetHash, expiration);
|
|
272
374
|
const normalized = normalizePayload(message);
|
|
273
375
|
return createEip712Payload(PAGINATED_DELETE_SIGNATURE_PAYLOAD_DEFINITION_V2, message.type, domain, normalized);
|
|
@@ -281,7 +383,7 @@ export function getEip712BrowserRequestPaginatedDeleteSignaturePayloadV2(schemaI
|
|
|
281
383
|
* @param actions Array of Add/Delete itemized actions
|
|
282
384
|
* @param domain
|
|
283
385
|
*/
|
|
284
|
-
export function getEip712BrowserRequestItemizedSignaturePayloadV2(schemaId, targetHash, expiration, actions, domain =
|
|
386
|
+
export function getEip712BrowserRequestItemizedSignaturePayloadV2(schemaId, targetHash, expiration, actions, domain = EIP712_DOMAIN_MAINNET) {
|
|
285
387
|
const message = createItemizedSignaturePayloadV2(schemaId, targetHash, expiration, actions);
|
|
286
388
|
const normalized = normalizePayload(message);
|
|
287
389
|
return createEip712Payload(ITEMIZED_SIGNATURE_PAYLOAD_DEFINITION_V2, message.type, domain, normalized);
|
|
@@ -293,7 +395,7 @@ export function getEip712BrowserRequestItemizedSignaturePayloadV2(schemaId, targ
|
|
|
293
395
|
* @param expirationBlock Block number after which this payload is invalid
|
|
294
396
|
* @param domain
|
|
295
397
|
*/
|
|
296
|
-
export function getEip712BrowserRequestClaimHandlePayload(handle, expirationBlock, domain =
|
|
398
|
+
export function getEip712BrowserRequestClaimHandlePayload(handle, expirationBlock, domain = EIP712_DOMAIN_MAINNET) {
|
|
297
399
|
const message = createClaimHandlePayload(handle, expirationBlock);
|
|
298
400
|
const normalized = normalizePayload(message);
|
|
299
401
|
return createEip712Payload(CLAIM_HANDLE_PAYLOAD_DEFINITION, message.type, domain, normalized);
|
|
@@ -304,11 +406,24 @@ export function getEip712BrowserRequestClaimHandlePayload(handle, expirationBloc
|
|
|
304
406
|
* @param publicKey The passkey’s public key (hex string or raw bytes)
|
|
305
407
|
* @param domain
|
|
306
408
|
*/
|
|
307
|
-
export function getEip712BrowserRequestPasskeyPublicKey(publicKey, domain =
|
|
409
|
+
export function getEip712BrowserRequestPasskeyPublicKey(publicKey, domain = EIP712_DOMAIN_MAINNET) {
|
|
308
410
|
const message = createPasskeyPublicKey(publicKey);
|
|
309
411
|
const normalized = normalizePayload(message);
|
|
310
412
|
return createEip712Payload(PASSKEY_PUBLIC_KEY_DEFINITION, message.type, domain, normalized);
|
|
311
413
|
}
|
|
414
|
+
/**
|
|
415
|
+
* Returns the EIP-712 browser request for a SiwfSignedRequestPayload for signing.
|
|
416
|
+
*
|
|
417
|
+
* @param callback Callback URL for login
|
|
418
|
+
* @param permissions One or more schema IDs (uint16) the provider may use
|
|
419
|
+
* @param userIdentifierAdminUrl Only used for custom integration situations.
|
|
420
|
+
* @param domain
|
|
421
|
+
*/
|
|
422
|
+
export function getEip712BrowserRequestSiwfSignedRequestPayload(callback, permissions, userIdentifierAdminUrl, domain = EIP712_DOMAIN_MAINNET) {
|
|
423
|
+
const message = createSiwfSignedRequestPayload(callback, permissions, userIdentifierAdminUrl);
|
|
424
|
+
const normalized = normalizePayload(message);
|
|
425
|
+
return createEip712Payload(SIWF_SIGNED_REQUEST_PAYLOAD_DEFINITION, message.type, domain, normalized);
|
|
426
|
+
}
|
|
312
427
|
function createEip712Payload(typeDefinition, primaryType, domain, message) {
|
|
313
428
|
return {
|
|
314
429
|
types: {
|
package/index.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import * as payloads from './payloads';
|
|
2
|
-
export * from './payloads';
|
|
3
|
-
export * from './signature';
|
|
4
|
-
export * from './signature.definitions';
|
|
5
|
-
export * from './address';
|
|
1
|
+
import * as payloads from './payloads.js';
|
|
2
|
+
export * from './payloads.js';
|
|
3
|
+
export * from './signature.js';
|
|
4
|
+
export * from './signature.definitions.js';
|
|
5
|
+
export * from './address.js';
|
|
6
6
|
declare const _default: {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
sign(secretKey: payloads.HexString, payload: payloads.SupportedPayload, chain: payloads.ChainType): Promise<payloads.EcdsaSignature>;
|
|
8
|
+
verifySignature(ethereumAddress: payloads.HexString, signature: payloads.HexString, payload: payloads.SupportedPayload, chain: payloads.ChainType): boolean;
|
|
9
9
|
createAddKeyData(msaId: string | bigint, newPublicKey: payloads.HexString | Uint8Array, expirationBlock: number): payloads.AddKeyData;
|
|
10
|
+
createAuthorizedKeyData(msaId: string | bigint, newPublicKey: payloads.HexString | Uint8Array, expirationBlock: number): payloads.AuthorizedKeyData;
|
|
10
11
|
createAddProvider(authorizedMsaId: string | bigint, schemaIds: number[], expirationBlock: number): payloads.AddProvider;
|
|
11
12
|
createClaimHandlePayload(handle: string, expirationBlock: number): payloads.ClaimHandlePayload;
|
|
12
13
|
createPasskeyPublicKey(publicKey: payloads.HexString | Uint8Array): payloads.PasskeyPublicKey;
|
|
@@ -15,22 +16,27 @@ declare const _default: {
|
|
|
15
16
|
createItemizedSignaturePayloadV2(schemaId: number, targetHash: number, expiration: number, actions: payloads.ItemizedAction[]): payloads.ItemizedSignaturePayloadV2;
|
|
16
17
|
createPaginatedDeleteSignaturePayloadV2(schemaId: number, pageId: number, targetHash: number, expiration: number): payloads.PaginatedDeleteSignaturePayloadV2;
|
|
17
18
|
createPaginatedUpsertSignaturePayloadV2(schemaId: number, pageId: number, targetHash: number, expiration: number, payload: payloads.HexString | Uint8Array): payloads.PaginatedUpsertSignaturePayloadV2;
|
|
19
|
+
createSiwfSignedRequestPayload(callback: string, permissions: number[], userIdentifierAdminUrl?: string): payloads.SiwfSignedRequestPayload;
|
|
20
|
+
createSiwfLoginRequestPayload(message: string): payloads.SiwfLoginRequestPayload;
|
|
18
21
|
getEip712BrowserRequestAddKeyData(msaId: string | bigint, newPublicKey: payloads.HexString | Uint8Array, expirationBlock: number, domain?: payloads.EipDomainPayload): unknown;
|
|
22
|
+
getEip712BrowserRequestAuthorizedKeyData(msaId: string | bigint, authorizedPublicKey: payloads.HexString | Uint8Array, expirationBlock: number, domain?: payloads.EipDomainPayload): unknown;
|
|
19
23
|
getEip712BrowserRequestAddProvider(authorizedMsaId: string | bigint, schemaIds: number[], expirationBlock: number, domain?: payloads.EipDomainPayload): unknown;
|
|
20
24
|
getEip712BrowserRequestPaginatedUpsertSignaturePayloadV2(schemaId: number, pageId: number, targetHash: number, expiration: number, payload: payloads.HexString | Uint8Array, domain?: payloads.EipDomainPayload): unknown;
|
|
21
25
|
getEip712BrowserRequestPaginatedDeleteSignaturePayloadV2(schemaId: number, pageId: number, targetHash: number, expiration: number, domain?: payloads.EipDomainPayload): unknown;
|
|
22
26
|
getEip712BrowserRequestItemizedSignaturePayloadV2(schemaId: number, targetHash: number, expiration: number, actions: payloads.ItemizedAction[], domain?: payloads.EipDomainPayload): unknown;
|
|
23
27
|
getEip712BrowserRequestClaimHandlePayload(handle: string, expirationBlock: number, domain?: payloads.EipDomainPayload): unknown;
|
|
24
28
|
getEip712BrowserRequestPasskeyPublicKey(publicKey: payloads.HexString | Uint8Array, domain?: payloads.EipDomainPayload): unknown;
|
|
25
|
-
|
|
26
|
-
|
|
29
|
+
getEip712BrowserRequestSiwfSignedRequestPayload(callback: string, permissions: number[], userIdentifierAdminUrl?: string, domain?: payloads.EipDomainPayload): unknown;
|
|
30
|
+
getEthereumRegularSigner(ethereumPair: import("@polkadot/keyring/types.js").KeyringPair): import("@polkadot/types/types/extrinsic.js").Signer;
|
|
31
|
+
getEthereumMessageSigner(ethereumPair: import("@polkadot/keyring/types.js").KeyringPair): import("@polkadot/types/types/extrinsic.js").Signer;
|
|
27
32
|
EIP712_DOMAIN_DEFINITION: {
|
|
28
33
|
EIP712Domain: {
|
|
29
34
|
name: string;
|
|
30
35
|
type: string;
|
|
31
36
|
}[];
|
|
32
37
|
};
|
|
33
|
-
|
|
38
|
+
EIP712_DOMAIN_MAINNET: payloads.EipDomainPayload;
|
|
39
|
+
EIP712_DOMAIN_TESTNET: payloads.EipDomainPayload;
|
|
34
40
|
ADD_PROVIDER_DEFINITION: {
|
|
35
41
|
AddProvider: {
|
|
36
42
|
name: string;
|
|
@@ -43,6 +49,12 @@ declare const _default: {
|
|
|
43
49
|
type: string;
|
|
44
50
|
}[];
|
|
45
51
|
};
|
|
52
|
+
AUTHORIZED_KEY_DATA_DEFINITION: {
|
|
53
|
+
AuthorizedKeyData: {
|
|
54
|
+
name: string;
|
|
55
|
+
type: string;
|
|
56
|
+
}[];
|
|
57
|
+
};
|
|
46
58
|
CLAIM_HANDLE_PAYLOAD_DEFINITION: {
|
|
47
59
|
ClaimHandlePayload: {
|
|
48
60
|
name: string;
|
|
@@ -77,13 +89,19 @@ declare const _default: {
|
|
|
77
89
|
type: string;
|
|
78
90
|
}[];
|
|
79
91
|
};
|
|
92
|
+
SIWF_SIGNED_REQUEST_PAYLOAD_DEFINITION: {
|
|
93
|
+
SiwfSignedRequestPayload: {
|
|
94
|
+
name: string;
|
|
95
|
+
type: string;
|
|
96
|
+
}[];
|
|
97
|
+
};
|
|
80
98
|
createRandomKey(): payloads.EthereumKeyPair;
|
|
81
|
-
ethereumAddressToKeyringPair(ethereumAddress: import("@polkadot/types/interfaces").H160): import("@polkadot/keyring/types").KeyringPair;
|
|
82
|
-
getUnifiedAddress(pair: import("@polkadot/keyring/types").KeyringPair): string;
|
|
83
|
-
getUnifiedPublicKey(pair: import("@polkadot/keyring/types").KeyringPair): Uint8Array;
|
|
99
|
+
ethereumAddressToKeyringPair(ethereumAddress: import("@polkadot/types/interfaces/types.js").H160): import("@polkadot/keyring/types.js").KeyringPair;
|
|
100
|
+
getUnifiedAddress(pair: import("@polkadot/keyring/types.js").KeyringPair): string;
|
|
101
|
+
getUnifiedPublicKey(pair: import("@polkadot/keyring/types.js").KeyringPair): Uint8Array;
|
|
84
102
|
reverseUnifiedAddressToEthereumAddress(unifiedAddress: payloads.HexString): payloads.HexString;
|
|
85
103
|
getSS58AccountFromEthereumAccount(accountId20Hex: string): string;
|
|
86
|
-
getKeyringPairFromSecp256k1PrivateKey(secretKey: Uint8Array): import("@polkadot/keyring/types").KeyringPair;
|
|
87
|
-
getAccountId20MultiAddress(pair: import("@polkadot/keyring/types").KeyringPair): payloads.Address20MultiAddress;
|
|
104
|
+
getKeyringPairFromSecp256k1PrivateKey(secretKey: Uint8Array): import("@polkadot/keyring/types.js").KeyringPair;
|
|
105
|
+
getAccountId20MultiAddress(pair: import("@polkadot/keyring/types.js").KeyringPair): payloads.Address20MultiAddress;
|
|
88
106
|
};
|
|
89
107
|
export default _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@frequency-chain/ethereum-utils",
|
|
3
|
-
"version": "1.17.0-
|
|
3
|
+
"version": "1.17.0-rc7",
|
|
4
4
|
"bugs": {
|
|
5
5
|
"url": "https://github.com/frequency-chain/frequency/issues"
|
|
6
6
|
},
|
|
@@ -15,9 +15,12 @@
|
|
|
15
15
|
"author": "frequency-chain",
|
|
16
16
|
"license": "Apache-2.0",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@polkadot/api": "^16.
|
|
19
|
-
"@polkadot/util": "13.5.
|
|
20
|
-
"ethers": "^6.14.
|
|
18
|
+
"@polkadot/api": "^16.2.2",
|
|
19
|
+
"@polkadot/util": "13.5.2",
|
|
20
|
+
"ethers": "^6.14.4"
|
|
21
|
+
},
|
|
22
|
+
"optionalDependencies": {
|
|
23
|
+
"@rollup/rollup-linux-x64-gnu": "^4.44.1"
|
|
21
24
|
},
|
|
22
25
|
"module": "./esm/index.js",
|
|
23
26
|
"types": "index.d.ts",
|
package/payloads.d.ts
CHANGED
|
@@ -65,16 +65,35 @@ export interface AddKeyData {
|
|
|
65
65
|
expiration: number;
|
|
66
66
|
newPublicKey: HexString;
|
|
67
67
|
}
|
|
68
|
+
export interface AuthorizedKeyData {
|
|
69
|
+
type: 'AuthorizedKeyData';
|
|
70
|
+
msaId: string;
|
|
71
|
+
expiration: number;
|
|
72
|
+
authorizedPublicKey: HexString;
|
|
73
|
+
}
|
|
68
74
|
export interface AddProvider {
|
|
69
75
|
type: 'AddProvider';
|
|
70
76
|
authorizedMsaId: string;
|
|
71
77
|
schemaIds: number[];
|
|
72
78
|
expiration: number;
|
|
73
79
|
}
|
|
74
|
-
export
|
|
80
|
+
export interface SiwfSignedRequestPayload {
|
|
81
|
+
type: 'SiwfSignedRequestPayload';
|
|
82
|
+
callback: string;
|
|
83
|
+
permissions: number[];
|
|
84
|
+
userIdentifierAdminUrl?: string;
|
|
85
|
+
}
|
|
86
|
+
export interface SiwfLoginRequestPayload {
|
|
87
|
+
type: 'SiwfLoginRequestPayload';
|
|
88
|
+
message: string;
|
|
89
|
+
}
|
|
90
|
+
export type SupportedPayload = PaginatedUpsertSignaturePayloadV2 | PaginatedDeleteSignaturePayloadV2 | ItemizedSignaturePayloadV2 | PasskeyPublicKey | ClaimHandlePayload | AddKeyData | AuthorizedKeyData | AddProvider | SiwfSignedRequestPayload | SiwfLoginRequestPayload;
|
|
91
|
+
export type NormalizedSupportedPayload = Omit<SupportedPayload, 'type'>;
|
|
75
92
|
export interface EipDomainPayload {
|
|
76
93
|
name: string;
|
|
77
94
|
version: string;
|
|
78
95
|
chainId: HexString;
|
|
79
96
|
verifyingContract: HexString;
|
|
80
97
|
}
|
|
98
|
+
export type SupportedPayloadTypes = SupportedPayload['type'];
|
|
99
|
+
export type SignatureType = 'EIP-712' | 'EIP-191';
|
package/signature.d.ts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { AddKeyData, AddProvider, ChainType, ClaimHandlePayload, EcdsaSignature, ItemizedSignaturePayloadV2, PaginatedDeleteSignaturePayloadV2, PaginatedUpsertSignaturePayloadV2, PasskeyPublicKey, SupportedPayload, HexString, AddItemizedAction, DeleteItemizedAction, ItemizedAction, EipDomainPayload } from './payloads';
|
|
1
|
+
import { AddKeyData, AuthorizedKeyData, AddProvider, ChainType, ClaimHandlePayload, EcdsaSignature, ItemizedSignaturePayloadV2, PaginatedDeleteSignaturePayloadV2, PaginatedUpsertSignaturePayloadV2, PasskeyPublicKey, SupportedPayload, HexString, AddItemizedAction, DeleteItemizedAction, ItemizedAction, EipDomainPayload, SiwfSignedRequestPayload, SiwfLoginRequestPayload } from './payloads.js';
|
|
2
2
|
import { KeyringPair } from '@polkadot/keyring/types';
|
|
3
3
|
import { Signer } from '@polkadot/types/types';
|
|
4
4
|
/**
|
|
5
|
-
* Signing EIP-712 compatible signature
|
|
5
|
+
* Signing EIP-712 or ERC-191 compatible signature based on payload
|
|
6
6
|
* @param secretKey
|
|
7
7
|
* @param payload
|
|
8
8
|
* @param chain
|
|
9
9
|
*/
|
|
10
|
-
export declare function
|
|
10
|
+
export declare function sign(secretKey: HexString, payload: SupportedPayload, chain: ChainType): Promise<EcdsaSignature>;
|
|
11
11
|
/**
|
|
12
|
-
* Verify EIP-712 signatures
|
|
12
|
+
* Verify EIP-712 and ERC-191 signatures based on payload
|
|
13
13
|
* @param ethereumAddress
|
|
14
14
|
* @param signature
|
|
15
15
|
* @param payload
|
|
16
16
|
* @param chain
|
|
17
17
|
*/
|
|
18
|
-
export declare function
|
|
18
|
+
export declare function verifySignature(ethereumAddress: HexString, signature: HexString, payload: SupportedPayload, chain: ChainType): boolean;
|
|
19
19
|
/**
|
|
20
20
|
* Build an AddKeyData payload for signature.
|
|
21
21
|
*
|
|
@@ -24,6 +24,14 @@ export declare function verifyEip712Signature(ethereumAddress: HexString, signat
|
|
|
24
24
|
* @param expirationBlock Block number after which this payload is invalid
|
|
25
25
|
*/
|
|
26
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;
|
|
27
35
|
/**
|
|
28
36
|
* Build an AddProvider payload for signature.
|
|
29
37
|
*
|
|
@@ -75,6 +83,20 @@ export declare function createPaginatedDeleteSignaturePayloadV2(schemaId: number
|
|
|
75
83
|
* @param payload HexString or Uint8Array data to upsert
|
|
76
84
|
*/
|
|
77
85
|
export declare function createPaginatedUpsertSignaturePayloadV2(schemaId: number, pageId: number, targetHash: number, expiration: number, payload: HexString | Uint8Array): PaginatedUpsertSignaturePayloadV2;
|
|
86
|
+
/**
|
|
87
|
+
* Build an SiwfSignedRequestPayload payload for signature.
|
|
88
|
+
*
|
|
89
|
+
* @param callback Callback URL for login
|
|
90
|
+
* @param permissions One or more schema IDs (uint16) the provider may use
|
|
91
|
+
* @param userIdentifierAdminUrl Only used for custom integration situations.
|
|
92
|
+
*/
|
|
93
|
+
export declare function createSiwfSignedRequestPayload(callback: string, permissions: number[], userIdentifierAdminUrl?: string): SiwfSignedRequestPayload;
|
|
94
|
+
/**
|
|
95
|
+
* Build an SiwfLoginRequestPayload payload for signature.
|
|
96
|
+
*
|
|
97
|
+
* @param message login message
|
|
98
|
+
*/
|
|
99
|
+
export declare function createSiwfLoginRequestPayload(message: string): SiwfLoginRequestPayload;
|
|
78
100
|
/**
|
|
79
101
|
* Returns the EIP-712 browser request for a AddKeyData for signing.
|
|
80
102
|
*
|
|
@@ -84,6 +106,15 @@ export declare function createPaginatedUpsertSignaturePayloadV2(schemaId: number
|
|
|
84
106
|
* @param domain
|
|
85
107
|
*/
|
|
86
108
|
export declare function getEip712BrowserRequestAddKeyData(msaId: string | bigint, newPublicKey: HexString | Uint8Array, expirationBlock: number, domain?: EipDomainPayload): unknown;
|
|
109
|
+
/**
|
|
110
|
+
* Returns the EIP-712 browser request for a AuthorizedKeyData for signing.
|
|
111
|
+
*
|
|
112
|
+
* @param msaId MSA ID (uint64) to add the key
|
|
113
|
+
* @param authorizedPublicKey 32 bytes public key to add in hex or Uint8Array
|
|
114
|
+
* @param expirationBlock Block number after which this payload is invalid
|
|
115
|
+
* @param domain
|
|
116
|
+
*/
|
|
117
|
+
export declare function getEip712BrowserRequestAuthorizedKeyData(msaId: string | bigint, authorizedPublicKey: HexString | Uint8Array, expirationBlock: number, domain?: EipDomainPayload): unknown;
|
|
87
118
|
/**
|
|
88
119
|
* Returns the EIP-712 browser request for a AddProvider for signing.
|
|
89
120
|
*
|
|
@@ -139,6 +170,15 @@ export declare function getEip712BrowserRequestClaimHandlePayload(handle: string
|
|
|
139
170
|
* @param domain
|
|
140
171
|
*/
|
|
141
172
|
export declare function getEip712BrowserRequestPasskeyPublicKey(publicKey: HexString | Uint8Array, domain?: EipDomainPayload): unknown;
|
|
173
|
+
/**
|
|
174
|
+
* Returns the EIP-712 browser request for a SiwfSignedRequestPayload for signing.
|
|
175
|
+
*
|
|
176
|
+
* @param callback Callback URL for login
|
|
177
|
+
* @param permissions One or more schema IDs (uint16) the provider may use
|
|
178
|
+
* @param userIdentifierAdminUrl Only used for custom integration situations.
|
|
179
|
+
* @param domain
|
|
180
|
+
*/
|
|
181
|
+
export declare function getEip712BrowserRequestSiwfSignedRequestPayload(callback: string, permissions: number[], userIdentifierAdminUrl?: string, domain?: EipDomainPayload): unknown;
|
|
142
182
|
/**
|
|
143
183
|
* Returns An ethereum compatible signature for the extrinsic
|
|
144
184
|
* @param ethereumPair
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { EipDomainPayload } from './payloads';
|
|
1
|
+
import { EipDomainPayload } from './payloads.js';
|
|
2
2
|
export declare const EIP712_DOMAIN_DEFINITION: {
|
|
3
3
|
EIP712Domain: {
|
|
4
4
|
name: string;
|
|
5
5
|
type: string;
|
|
6
6
|
}[];
|
|
7
7
|
};
|
|
8
|
-
export declare const
|
|
8
|
+
export declare const EIP712_DOMAIN_MAINNET: EipDomainPayload;
|
|
9
|
+
export declare const EIP712_DOMAIN_TESTNET: EipDomainPayload;
|
|
9
10
|
export declare const ADD_PROVIDER_DEFINITION: {
|
|
10
11
|
AddProvider: {
|
|
11
12
|
name: string;
|
|
@@ -18,6 +19,12 @@ export declare const ADD_KEY_DATA_DEFINITION: {
|
|
|
18
19
|
type: string;
|
|
19
20
|
}[];
|
|
20
21
|
};
|
|
22
|
+
export declare const AUTHORIZED_KEY_DATA_DEFINITION: {
|
|
23
|
+
AuthorizedKeyData: {
|
|
24
|
+
name: string;
|
|
25
|
+
type: string;
|
|
26
|
+
}[];
|
|
27
|
+
};
|
|
21
28
|
export declare const CLAIM_HANDLE_PAYLOAD_DEFINITION: {
|
|
22
29
|
ClaimHandlePayload: {
|
|
23
30
|
name: string;
|
|
@@ -52,3 +59,61 @@ export declare const ITEMIZED_SIGNATURE_PAYLOAD_DEFINITION_V2: {
|
|
|
52
59
|
type: string;
|
|
53
60
|
}[];
|
|
54
61
|
};
|
|
62
|
+
export declare const SIWF_SIGNED_REQUEST_PAYLOAD_DEFINITION: {
|
|
63
|
+
SiwfSignedRequestPayload: {
|
|
64
|
+
name: string;
|
|
65
|
+
type: string;
|
|
66
|
+
}[];
|
|
67
|
+
};
|
|
68
|
+
declare const PAYLOAD_DEFINITIONS: ({
|
|
69
|
+
AddProvider: {
|
|
70
|
+
name: string;
|
|
71
|
+
type: string;
|
|
72
|
+
}[];
|
|
73
|
+
} | {
|
|
74
|
+
AddKeyData: {
|
|
75
|
+
name: string;
|
|
76
|
+
type: string;
|
|
77
|
+
}[];
|
|
78
|
+
} | {
|
|
79
|
+
AuthorizedKeyData: {
|
|
80
|
+
name: string;
|
|
81
|
+
type: string;
|
|
82
|
+
}[];
|
|
83
|
+
} | {
|
|
84
|
+
ClaimHandlePayload: {
|
|
85
|
+
name: string;
|
|
86
|
+
type: string;
|
|
87
|
+
}[];
|
|
88
|
+
} | {
|
|
89
|
+
PasskeyPublicKey: {
|
|
90
|
+
name: string;
|
|
91
|
+
type: string;
|
|
92
|
+
}[];
|
|
93
|
+
} | {
|
|
94
|
+
PaginatedDeleteSignaturePayloadV2: {
|
|
95
|
+
name: string;
|
|
96
|
+
type: string;
|
|
97
|
+
}[];
|
|
98
|
+
} | {
|
|
99
|
+
PaginatedUpsertSignaturePayloadV2: {
|
|
100
|
+
name: string;
|
|
101
|
+
type: string;
|
|
102
|
+
}[];
|
|
103
|
+
} | {
|
|
104
|
+
ItemizedSignaturePayloadV2: {
|
|
105
|
+
name: string;
|
|
106
|
+
type: string;
|
|
107
|
+
}[];
|
|
108
|
+
ItemAction: {
|
|
109
|
+
name: string;
|
|
110
|
+
type: string;
|
|
111
|
+
}[];
|
|
112
|
+
} | {
|
|
113
|
+
SiwfSignedRequestPayload: {
|
|
114
|
+
name: string;
|
|
115
|
+
type: string;
|
|
116
|
+
}[];
|
|
117
|
+
})[];
|
|
118
|
+
export type SupportedPayloadDefinitions = (typeof PAYLOAD_DEFINITIONS)[number];
|
|
119
|
+
export {};
|
package/utils.d.ts
CHANGED