@frequency-chain/ethereum-utils 1.17.0-rc5 → 1.17.0-rc6
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 +1297 -862
- package/browser/frequency-ethereum-utils.umd.min.js +1275 -848
- package/cjs/index.js +8 -8
- package/cjs/signature.definitions.js +44 -1
- package/cjs/signature.js +186 -64
- package/esm/index.js +8 -8
- package/esm/signature.definitions.js +43 -0
- package/esm/signature.js +132 -15
- package/index.d.ts +31 -14
- package/package.json +7 -4
- package/payloads.d.ts +20 -1
- package/signature.d.ts +45 -5
- package/signature.definitions.d.ts +65 -1
- package/utils.d.ts +1 -1
package/esm/signature.js
CHANGED
|
@@ -1,36 +1,56 @@
|
|
|
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, EIP712_DOMAIN_DEFAULT, EIP712_DOMAIN_DEFINITION, ITEMIZED_SIGNATURE_PAYLOAD_DEFINITION_V2, PAGINATED_DELETE_SIGNATURE_PAYLOAD_DEFINITION_V2, PAGINATED_UPSERT_SIGNATURE_PAYLOAD_DEFINITION_V2, PASSKEY_PUBLIC_KEY_DEFINITION, } from './signature.definitions';
|
|
5
|
+
import { ADD_KEY_DATA_DEFINITION, ADD_PROVIDER_DEFINITION, AUTHORIZED_KEY_DATA_DEFINITION, CLAIM_HANDLE_PAYLOAD_DEFINITION, EIP712_DOMAIN_DEFAULT, 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, } 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 = 'Mainnet-Frequency') {
|
|
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 chainID for different networks
|
|
20
|
+
// TODO: use correct contract address for different payloads
|
|
21
|
+
signature = await wallet.signTypedData(EIP712_DOMAIN_DEFAULT, getTypesFor(payload.type), normalizedPayload);
|
|
22
|
+
break;
|
|
23
|
+
case 'EIP-191':
|
|
24
|
+
signature = await wallet.signMessage(payload.message);
|
|
25
|
+
break;
|
|
26
|
+
default:
|
|
27
|
+
throw new Error(`Unsupported signature type : ${signatureType}`);
|
|
28
|
+
}
|
|
19
29
|
return { Ecdsa: signature };
|
|
20
30
|
}
|
|
21
31
|
/**
|
|
22
|
-
* Verify EIP-712 signatures
|
|
32
|
+
* Verify EIP-712 and ERC-191 signatures based on payload
|
|
23
33
|
* @param ethereumAddress
|
|
24
34
|
* @param signature
|
|
25
35
|
* @param payload
|
|
26
36
|
* @param chain
|
|
27
37
|
*/
|
|
28
|
-
export function
|
|
29
|
-
const
|
|
38
|
+
export function verifySignature(ethereumAddress, signature, payload, chain = 'Mainnet-Frequency') {
|
|
39
|
+
const signatureType = getSignatureType(payload.type);
|
|
30
40
|
const normalizedPayload = normalizePayload(payload);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
41
|
+
let recoveredAddress;
|
|
42
|
+
switch (signatureType) {
|
|
43
|
+
case 'EIP-712':
|
|
44
|
+
// TODO: use correct chainID for different networks
|
|
45
|
+
// TODO: use correct contract address for different payloads
|
|
46
|
+
recoveredAddress = ethers.verifyTypedData(EIP712_DOMAIN_DEFAULT, getTypesFor(payload.type), normalizedPayload, signature);
|
|
47
|
+
break;
|
|
48
|
+
case 'EIP-191':
|
|
49
|
+
recoveredAddress = ethers.verifyMessage(payload.message, signature);
|
|
50
|
+
break;
|
|
51
|
+
default:
|
|
52
|
+
throw new Error(`Unsupported signature type : ${signatureType}`);
|
|
53
|
+
}
|
|
34
54
|
return recoveredAddress.toLowerCase() === ethereumAddress.toLowerCase();
|
|
35
55
|
}
|
|
36
56
|
function normalizePayload(payload) {
|
|
@@ -42,6 +62,7 @@ function normalizePayload(payload) {
|
|
|
42
62
|
case 'PasskeyPublicKey':
|
|
43
63
|
case 'ClaimHandlePayload':
|
|
44
64
|
case 'AddProvider':
|
|
65
|
+
case 'SiwfLoginRequestPayload':
|
|
45
66
|
break;
|
|
46
67
|
case 'AddKeyData':
|
|
47
68
|
// convert to 20 bytes ethereum address for signature
|
|
@@ -50,6 +71,18 @@ function normalizePayload(payload) {
|
|
|
50
71
|
}
|
|
51
72
|
clonedPayload.newPublicKey = clonedPayload.newPublicKey.toLowerCase();
|
|
52
73
|
break;
|
|
74
|
+
case 'AuthorizedKeyData':
|
|
75
|
+
// convert to 20 bytes ethereum address for signature
|
|
76
|
+
if (clonedPayload.authorizedPublicKey.length !== 42) {
|
|
77
|
+
clonedPayload.authorizedPublicKey = reverseUnifiedAddressToEthereumAddress(payload.authorizedPublicKey);
|
|
78
|
+
}
|
|
79
|
+
clonedPayload.authorizedPublicKey = clonedPayload.authorizedPublicKey.toLowerCase();
|
|
80
|
+
break;
|
|
81
|
+
case 'SiwfSignedRequestPayload':
|
|
82
|
+
if (clonedPayload.userIdentifierAdminUrl == null) {
|
|
83
|
+
clonedPayload.userIdentifierAdminUrl = '';
|
|
84
|
+
}
|
|
85
|
+
break;
|
|
53
86
|
default:
|
|
54
87
|
throw new Error(`Unsupported payload type: ${JSON.stringify(payload)}`);
|
|
55
88
|
}
|
|
@@ -65,7 +98,10 @@ function getTypesFor(payloadType) {
|
|
|
65
98
|
PasskeyPublicKey: PASSKEY_PUBLIC_KEY_DEFINITION,
|
|
66
99
|
ClaimHandlePayload: CLAIM_HANDLE_PAYLOAD_DEFINITION,
|
|
67
100
|
AddKeyData: ADD_KEY_DATA_DEFINITION,
|
|
101
|
+
AuthorizedKeyData: AUTHORIZED_KEY_DATA_DEFINITION,
|
|
68
102
|
AddProvider: ADD_PROVIDER_DEFINITION,
|
|
103
|
+
// offchain signatures
|
|
104
|
+
SiwfSignedRequestPayload: SIWF_SIGNED_REQUEST_PAYLOAD_DEFINITION,
|
|
69
105
|
};
|
|
70
106
|
const definition = PAYLOAD_TYPE_DEFINITIONS[payloadType];
|
|
71
107
|
if (!definition) {
|
|
@@ -73,6 +109,12 @@ function getTypesFor(payloadType) {
|
|
|
73
109
|
}
|
|
74
110
|
return definition;
|
|
75
111
|
}
|
|
112
|
+
function getSignatureType(payloadType) {
|
|
113
|
+
if (payloadType === 'SiwfLoginRequestPayload') {
|
|
114
|
+
return 'EIP-191';
|
|
115
|
+
}
|
|
116
|
+
return 'EIP-712';
|
|
117
|
+
}
|
|
76
118
|
/**
|
|
77
119
|
* Build an AddKeyData payload for signature.
|
|
78
120
|
*
|
|
@@ -93,6 +135,26 @@ export function createAddKeyData(msaId, newPublicKey, expirationBlock) {
|
|
|
93
135
|
newPublicKey: parsedNewPublicKey,
|
|
94
136
|
};
|
|
95
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Build an AuthorizedKeyData payload for signature.
|
|
140
|
+
*
|
|
141
|
+
* @param msaId MSA ID (uint64) to add the key
|
|
142
|
+
* @param authorizedPublicKey 32 bytes public key to authorize in hex or Uint8Array
|
|
143
|
+
* @param expirationBlock Block number after which this payload is invalid
|
|
144
|
+
*/
|
|
145
|
+
export function createAuthorizedKeyData(msaId, newPublicKey, expirationBlock) {
|
|
146
|
+
const parsedMsaId = typeof msaId === 'string' ? msaId : `${msaId}`;
|
|
147
|
+
const parsedNewPublicKey = typeof newPublicKey === 'object' ? u8aToHex(newPublicKey) : newPublicKey;
|
|
148
|
+
assert(isValidUint64String(parsedMsaId), 'msaId should be a valid uint64');
|
|
149
|
+
assert(isValidUint32(expirationBlock), 'expiration should be a valid uint32');
|
|
150
|
+
assert(isHexString(parsedNewPublicKey), 'newPublicKey should be valid hex');
|
|
151
|
+
return {
|
|
152
|
+
type: 'AuthorizedKeyData',
|
|
153
|
+
msaId: parsedMsaId,
|
|
154
|
+
expiration: expirationBlock,
|
|
155
|
+
authorizedPublicKey: parsedNewPublicKey,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
96
158
|
/**
|
|
97
159
|
* Build an AddProvider payload for signature.
|
|
98
160
|
*
|
|
@@ -217,6 +279,35 @@ export function createPaginatedUpsertSignaturePayloadV2(schemaId, pageId, target
|
|
|
217
279
|
payload: parsedPayload,
|
|
218
280
|
};
|
|
219
281
|
}
|
|
282
|
+
/**
|
|
283
|
+
* Build an SiwfSignedRequestPayload payload for signature.
|
|
284
|
+
*
|
|
285
|
+
* @param callback Callback URL for login
|
|
286
|
+
* @param permissions One or more schema IDs (uint16) the provider may use
|
|
287
|
+
* @param userIdentifierAdminUrl Only used for custom integration situations.
|
|
288
|
+
*/
|
|
289
|
+
export function createSiwfSignedRequestPayload(callback, permissions, userIdentifierAdminUrl) {
|
|
290
|
+
permissions.forEach((schemaId) => {
|
|
291
|
+
assert(isValidUint16(schemaId), 'permission should be a valid uint16');
|
|
292
|
+
});
|
|
293
|
+
return {
|
|
294
|
+
type: 'SiwfSignedRequestPayload',
|
|
295
|
+
callback: callback,
|
|
296
|
+
permissions,
|
|
297
|
+
userIdentifierAdminUrl,
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Build an SiwfLoginRequestPayload payload for signature.
|
|
302
|
+
*
|
|
303
|
+
* @param message login message
|
|
304
|
+
*/
|
|
305
|
+
export function createSiwfLoginRequestPayload(message) {
|
|
306
|
+
return {
|
|
307
|
+
type: 'SiwfLoginRequestPayload',
|
|
308
|
+
message,
|
|
309
|
+
};
|
|
310
|
+
}
|
|
220
311
|
/**
|
|
221
312
|
* Returns the EIP-712 browser request for a AddKeyData for signing.
|
|
222
313
|
*
|
|
@@ -230,6 +321,19 @@ export function getEip712BrowserRequestAddKeyData(msaId, newPublicKey, expiratio
|
|
|
230
321
|
const normalized = normalizePayload(message);
|
|
231
322
|
return createEip712Payload(ADD_KEY_DATA_DEFINITION, message.type, domain, normalized);
|
|
232
323
|
}
|
|
324
|
+
/**
|
|
325
|
+
* Returns the EIP-712 browser request for a AuthorizedKeyData for signing.
|
|
326
|
+
*
|
|
327
|
+
* @param msaId MSA ID (uint64) to add the key
|
|
328
|
+
* @param authorizedPublicKey 32 bytes public key to add in hex or Uint8Array
|
|
329
|
+
* @param expirationBlock Block number after which this payload is invalid
|
|
330
|
+
* @param domain
|
|
331
|
+
*/
|
|
332
|
+
export function getEip712BrowserRequestAuthorizedKeyData(msaId, authorizedPublicKey, expirationBlock, domain = EIP712_DOMAIN_DEFAULT) {
|
|
333
|
+
const message = createAuthorizedKeyData(msaId, authorizedPublicKey, expirationBlock);
|
|
334
|
+
const normalized = normalizePayload(message);
|
|
335
|
+
return createEip712Payload(AUTHORIZED_KEY_DATA_DEFINITION, message.type, domain, normalized);
|
|
336
|
+
}
|
|
233
337
|
/**
|
|
234
338
|
* Returns the EIP-712 browser request for a AddProvider for signing.
|
|
235
339
|
*
|
|
@@ -309,6 +413,19 @@ export function getEip712BrowserRequestPasskeyPublicKey(publicKey, domain = EIP7
|
|
|
309
413
|
const normalized = normalizePayload(message);
|
|
310
414
|
return createEip712Payload(PASSKEY_PUBLIC_KEY_DEFINITION, message.type, domain, normalized);
|
|
311
415
|
}
|
|
416
|
+
/**
|
|
417
|
+
* Returns the EIP-712 browser request for a SiwfSignedRequestPayload for signing.
|
|
418
|
+
*
|
|
419
|
+
* @param callback Callback URL for login
|
|
420
|
+
* @param permissions One or more schema IDs (uint16) the provider may use
|
|
421
|
+
* @param userIdentifierAdminUrl Only used for custom integration situations.
|
|
422
|
+
* @param domain
|
|
423
|
+
*/
|
|
424
|
+
export function getEip712BrowserRequestSiwfSignedRequestPayload(callback, permissions, userIdentifierAdminUrl, domain = EIP712_DOMAIN_DEFAULT) {
|
|
425
|
+
const message = createSiwfSignedRequestPayload(callback, permissions, userIdentifierAdminUrl);
|
|
426
|
+
const normalized = normalizePayload(message);
|
|
427
|
+
return createEip712Payload(SIWF_SIGNED_REQUEST_PAYLOAD_DEFINITION, message.type, domain, normalized);
|
|
428
|
+
}
|
|
312
429
|
function createEip712Payload(typeDefinition, primaryType, domain, message) {
|
|
313
430
|
return {
|
|
314
431
|
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,15 +16,19 @@ 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;
|
|
@@ -43,6 +48,12 @@ declare const _default: {
|
|
|
43
48
|
type: string;
|
|
44
49
|
}[];
|
|
45
50
|
};
|
|
51
|
+
AUTHORIZED_KEY_DATA_DEFINITION: {
|
|
52
|
+
AuthorizedKeyData: {
|
|
53
|
+
name: string;
|
|
54
|
+
type: string;
|
|
55
|
+
}[];
|
|
56
|
+
};
|
|
46
57
|
CLAIM_HANDLE_PAYLOAD_DEFINITION: {
|
|
47
58
|
ClaimHandlePayload: {
|
|
48
59
|
name: string;
|
|
@@ -77,13 +88,19 @@ declare const _default: {
|
|
|
77
88
|
type: string;
|
|
78
89
|
}[];
|
|
79
90
|
};
|
|
91
|
+
SIWF_SIGNED_REQUEST_PAYLOAD_DEFINITION: {
|
|
92
|
+
SiwfSignedRequestPayload: {
|
|
93
|
+
name: string;
|
|
94
|
+
type: string;
|
|
95
|
+
}[];
|
|
96
|
+
};
|
|
80
97
|
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;
|
|
98
|
+
ethereumAddressToKeyringPair(ethereumAddress: import("@polkadot/types/interfaces/types.js").H160): import("@polkadot/keyring/types.js").KeyringPair;
|
|
99
|
+
getUnifiedAddress(pair: import("@polkadot/keyring/types.js").KeyringPair): string;
|
|
100
|
+
getUnifiedPublicKey(pair: import("@polkadot/keyring/types.js").KeyringPair): Uint8Array;
|
|
84
101
|
reverseUnifiedAddressToEthereumAddress(unifiedAddress: payloads.HexString): payloads.HexString;
|
|
85
102
|
getSS58AccountFromEthereumAccount(accountId20Hex: string): string;
|
|
86
|
-
getKeyringPairFromSecp256k1PrivateKey(secretKey: Uint8Array): import("@polkadot/keyring/types").KeyringPair;
|
|
87
|
-
getAccountId20MultiAddress(pair: import("@polkadot/keyring/types").KeyringPair): payloads.Address20MultiAddress;
|
|
103
|
+
getKeyringPairFromSecp256k1PrivateKey(secretKey: Uint8Array): import("@polkadot/keyring/types.js").KeyringPair;
|
|
104
|
+
getAccountId20MultiAddress(pair: import("@polkadot/keyring/types.js").KeyringPair): payloads.Address20MultiAddress;
|
|
88
105
|
};
|
|
89
106
|
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-rc6",
|
|
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.1",
|
|
19
|
+
"@polkadot/util": "13.5.2",
|
|
20
|
+
"ethers": "^6.14.4"
|
|
21
|
+
},
|
|
22
|
+
"optionalDependencies": {
|
|
23
|
+
"@rollup/rollup-linux-x64-gnu": "^4.43.0"
|
|
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,4 +1,4 @@
|
|
|
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;
|
|
@@ -18,6 +18,12 @@ export declare const ADD_KEY_DATA_DEFINITION: {
|
|
|
18
18
|
type: string;
|
|
19
19
|
}[];
|
|
20
20
|
};
|
|
21
|
+
export declare const AUTHORIZED_KEY_DATA_DEFINITION: {
|
|
22
|
+
AuthorizedKeyData: {
|
|
23
|
+
name: string;
|
|
24
|
+
type: string;
|
|
25
|
+
}[];
|
|
26
|
+
};
|
|
21
27
|
export declare const CLAIM_HANDLE_PAYLOAD_DEFINITION: {
|
|
22
28
|
ClaimHandlePayload: {
|
|
23
29
|
name: string;
|
|
@@ -52,3 +58,61 @@ export declare const ITEMIZED_SIGNATURE_PAYLOAD_DEFINITION_V2: {
|
|
|
52
58
|
type: string;
|
|
53
59
|
}[];
|
|
54
60
|
};
|
|
61
|
+
export declare const SIWF_SIGNED_REQUEST_PAYLOAD_DEFINITION: {
|
|
62
|
+
SiwfSignedRequestPayload: {
|
|
63
|
+
name: string;
|
|
64
|
+
type: string;
|
|
65
|
+
}[];
|
|
66
|
+
};
|
|
67
|
+
declare const PAYLOAD_DEFINITIONS: ({
|
|
68
|
+
AddProvider: {
|
|
69
|
+
name: string;
|
|
70
|
+
type: string;
|
|
71
|
+
}[];
|
|
72
|
+
} | {
|
|
73
|
+
AddKeyData: {
|
|
74
|
+
name: string;
|
|
75
|
+
type: string;
|
|
76
|
+
}[];
|
|
77
|
+
} | {
|
|
78
|
+
AuthorizedKeyData: {
|
|
79
|
+
name: string;
|
|
80
|
+
type: string;
|
|
81
|
+
}[];
|
|
82
|
+
} | {
|
|
83
|
+
ClaimHandlePayload: {
|
|
84
|
+
name: string;
|
|
85
|
+
type: string;
|
|
86
|
+
}[];
|
|
87
|
+
} | {
|
|
88
|
+
PasskeyPublicKey: {
|
|
89
|
+
name: string;
|
|
90
|
+
type: string;
|
|
91
|
+
}[];
|
|
92
|
+
} | {
|
|
93
|
+
PaginatedDeleteSignaturePayloadV2: {
|
|
94
|
+
name: string;
|
|
95
|
+
type: string;
|
|
96
|
+
}[];
|
|
97
|
+
} | {
|
|
98
|
+
PaginatedUpsertSignaturePayloadV2: {
|
|
99
|
+
name: string;
|
|
100
|
+
type: string;
|
|
101
|
+
}[];
|
|
102
|
+
} | {
|
|
103
|
+
ItemizedSignaturePayloadV2: {
|
|
104
|
+
name: string;
|
|
105
|
+
type: string;
|
|
106
|
+
}[];
|
|
107
|
+
ItemAction: {
|
|
108
|
+
name: string;
|
|
109
|
+
type: string;
|
|
110
|
+
}[];
|
|
111
|
+
} | {
|
|
112
|
+
SiwfSignedRequestPayload: {
|
|
113
|
+
name: string;
|
|
114
|
+
type: string;
|
|
115
|
+
}[];
|
|
116
|
+
})[];
|
|
117
|
+
export type SupportedPayloadDefinitions = (typeof PAYLOAD_DEFINITIONS)[number];
|
|
118
|
+
export {};
|
package/utils.d.ts
CHANGED