@keetanetwork/keetanet-client 0.10.2
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/._version.d.ts +0 -0
- package/LICENSE +35 -0
- package/api/index.d.ts +181 -0
- package/api/node.d.ts +216 -0
- package/api/vote.d.ts +25 -0
- package/client/builder.d.ts +129 -0
- package/client/client_common_tests.d.ts +72 -0
- package/client/index-browser.d.ts +243 -0
- package/client/index-browser.js +141899 -0
- package/client/index.d.ts +243 -0
- package/client/index.js +89118 -0
- package/config/index.d.ts +62 -0
- package/lib/account.d.ts +544 -0
- package/lib/block/index.d.ts +181 -0
- package/lib/block/operations.d.ts +407 -0
- package/lib/bootstrap.d.ts +27 -0
- package/lib/error/account.d.ts +9 -0
- package/lib/error/block.d.ts +9 -0
- package/lib/error/client.d.ts +9 -0
- package/lib/error/index.d.ts +20 -0
- package/lib/error/kv.d.ts +9 -0
- package/lib/error/ledger.d.ts +12 -0
- package/lib/error/permissions.d.ts +9 -0
- package/lib/error/vote.d.ts +9 -0
- package/lib/index.d.ts +39 -0
- package/lib/kv/index.d.ts +22 -0
- package/lib/kv/index.test.data.d.ts +9 -0
- package/lib/kv/kv_dynamodb.d.ts +20 -0
- package/lib/kv/kv_memory.d.ts +17 -0
- package/lib/kv/kv_redis.d.ts +22 -0
- package/lib/kv/providers.d.ts +9 -0
- package/lib/ledger/cache.d.ts +14 -0
- package/lib/ledger/common.d.ts +115 -0
- package/lib/ledger/db_dynamodb.d.ts +129 -0
- package/lib/ledger/db_memory.d.ts +6 -0
- package/lib/ledger/db_postgres.d.ts +70 -0
- package/lib/ledger/db_spanner.d.ts +116 -0
- package/lib/ledger/db_spanner_helper.d.ts +487 -0
- package/lib/ledger/db_sqlite.d.ts +64 -0
- package/lib/ledger/drivers.d.ts +7 -0
- package/lib/ledger/effects.d.ts +78 -0
- package/lib/ledger/index.d.ts +312 -0
- package/lib/ledger/types.d.ts +49 -0
- package/lib/node/index.d.ts +114 -0
- package/lib/node/local.d.ts +30 -0
- package/lib/node/timing.d.ts +12 -0
- package/lib/node/utils.d.ts +4 -0
- package/lib/p2p.d.ts +300 -0
- package/lib/permissions.d.ts +121 -0
- package/lib/pubsub/index.d.ts +7 -0
- package/lib/pubsub/providers.d.ts +7 -0
- package/lib/pubsub/ps_memory.d.ts +9 -0
- package/lib/pubsub/ps_redis.d.ts +10 -0
- package/lib/stats.d.ts +51 -0
- package/lib/utils/asn1.d.ts +205 -0
- package/lib/utils/bitfield.d.ts +13 -0
- package/lib/utils/bloom.d.ts +6 -0
- package/lib/utils/buffer.d.ts +27 -0
- package/lib/utils/certificate.d.ts +340 -0
- package/lib/utils/conversion.d.ts +46 -0
- package/lib/utils/dynamodb.d.ts +17 -0
- package/lib/utils/ed2curve.d.ts +7 -0
- package/lib/utils/hash.d.ts +17 -0
- package/lib/utils/helper.d.ts +67 -0
- package/lib/utils/helper_testing.d.ts +37 -0
- package/lib/utils/initial.d.ts +32 -0
- package/lib/utils/never.d.ts +7 -0
- package/lib/utils/redis.d.ts +11 -0
- package/lib/vote.d.ts +273 -0
- package/package.json +35 -0
- package/version.d.ts +2 -0
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import Account from '../lib/account';
|
|
2
|
+
/**
|
|
3
|
+
* Known Networks that exist in the configuration database
|
|
4
|
+
*/
|
|
5
|
+
export declare const networksArray: readonly ["production", "staging", "beta", "test", "dev"];
|
|
6
|
+
export type Networks = typeof networksArray[number];
|
|
7
|
+
export type NetworkOrID = Networks | bigint;
|
|
8
|
+
export declare const NetworkIDs: {
|
|
9
|
+
[network in Networks]: bigint;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Endpoints for reaching a Node
|
|
13
|
+
*/
|
|
14
|
+
export type Endpoints = {
|
|
15
|
+
api: string;
|
|
16
|
+
p2p: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Definition of a Representative
|
|
20
|
+
*/
|
|
21
|
+
export type Representative = {
|
|
22
|
+
key: Account;
|
|
23
|
+
endpoints: Endpoints;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Network Configuration for a Network
|
|
27
|
+
*/
|
|
28
|
+
export type NetworkConfig = {
|
|
29
|
+
networkAlias: Networks;
|
|
30
|
+
network: bigint;
|
|
31
|
+
initialTrustedAccount: Account;
|
|
32
|
+
representatives: Representative[];
|
|
33
|
+
validation: ValidationConfig;
|
|
34
|
+
publishAidURL?: string;
|
|
35
|
+
};
|
|
36
|
+
interface TextValidationRule {
|
|
37
|
+
regex: RegExp;
|
|
38
|
+
maxLength: number;
|
|
39
|
+
canBeEmpty?: boolean;
|
|
40
|
+
}
|
|
41
|
+
export interface ValidationConfig {
|
|
42
|
+
accountInfoFieldRules: {
|
|
43
|
+
name: TextValidationRule;
|
|
44
|
+
description: TextValidationRule;
|
|
45
|
+
metadata: TextValidationRule;
|
|
46
|
+
};
|
|
47
|
+
permissions: {
|
|
48
|
+
maxExternalOffset: number;
|
|
49
|
+
};
|
|
50
|
+
blockOperations: {
|
|
51
|
+
external: TextValidationRule;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export declare const baseValidationConfig: ValidationConfig;
|
|
55
|
+
export declare function getNetworkAlias(networkOrID: bigint | Networks): Networks;
|
|
56
|
+
export declare function getValidation(networkOrID: bigint | Networks): ValidationConfig;
|
|
57
|
+
/**
|
|
58
|
+
* Get the Default Configuration for a network in the configuration database
|
|
59
|
+
*/
|
|
60
|
+
export declare function getDefaultConfig(network: Networks): NetworkConfig;
|
|
61
|
+
export declare function isNetwork(network: any): network is Networks;
|
|
62
|
+
export {};
|
package/lib/account.d.ts
ADDED
|
@@ -0,0 +1,544 @@
|
|
|
1
|
+
import BufferStorage from './utils/buffer';
|
|
2
|
+
import { BufferStorageASN1 } from './utils/asn1';
|
|
3
|
+
import { BlockHash } from './block';
|
|
4
|
+
/**
|
|
5
|
+
* Account encoding prefixes
|
|
6
|
+
*/
|
|
7
|
+
declare const AccountPrefixes: readonly ["keeta_", "tyblocks_"];
|
|
8
|
+
type AccountPrefix = typeof AccountPrefixes[any];
|
|
9
|
+
/**
|
|
10
|
+
* Account key algorithms specify how the key should be used for validation,
|
|
11
|
+
* signing, and encoding.
|
|
12
|
+
*/
|
|
13
|
+
export declare enum AccountKeyAlgorithm {
|
|
14
|
+
ECDSA_SECP256K1 = 0,
|
|
15
|
+
ED25519 = 1,
|
|
16
|
+
NETWORK = 2,
|
|
17
|
+
TOKEN = 3,
|
|
18
|
+
STORAGE = 4,
|
|
19
|
+
ECDSA_SECP256R1 = 6
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Type for ASN.1 encoded public keys -- this is equivalent to @see ValidateASN1.SchemaMap<typeof publicKeyASN1Schema>
|
|
23
|
+
* but does not reference a complex type which may exceed TypeScripts limits
|
|
24
|
+
*/
|
|
25
|
+
type publicKeyASN1 = [
|
|
26
|
+
algorithmInfo: {
|
|
27
|
+
type: 'oid';
|
|
28
|
+
oid: string;
|
|
29
|
+
}[],
|
|
30
|
+
publicKey: {
|
|
31
|
+
type: 'bitstring';
|
|
32
|
+
value: Buffer;
|
|
33
|
+
}
|
|
34
|
+
];
|
|
35
|
+
declare const identifierKeyTypes: readonly [AccountKeyAlgorithm.NETWORK, AccountKeyAlgorithm.TOKEN, AccountKeyAlgorithm.STORAGE];
|
|
36
|
+
export type IdentifierKeyAlgorithm = typeof identifierKeyTypes[any];
|
|
37
|
+
/**
|
|
38
|
+
* Things we can use to construct a key from
|
|
39
|
+
*/
|
|
40
|
+
type InputKeyTypes = ConstructorParameters<typeof BufferStorage>[0];
|
|
41
|
+
/**
|
|
42
|
+
* Public Keys should have a mechanism to get the ASN.1 encoded value
|
|
43
|
+
*/
|
|
44
|
+
interface PublicKeyStorage extends BufferStorage {
|
|
45
|
+
ASN1: BufferStorageASN1<publicKeyASN1>;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Keys in Ed25519 and EcDSA secp256k1/secp256r1 are 256-bits long
|
|
49
|
+
*/
|
|
50
|
+
declare class KeyStorage extends BufferStorage {
|
|
51
|
+
static isInstance: (obj: any, strict?: boolean) => obj is KeyStorage;
|
|
52
|
+
constructor(key: InputKeyTypes);
|
|
53
|
+
}
|
|
54
|
+
declare class ECDSASECP256K1PrivateKey extends KeyStorage {
|
|
55
|
+
static isInstance: (obj: any, strict?: boolean) => obj is ECDSASECP256K1PrivateKey;
|
|
56
|
+
}
|
|
57
|
+
declare class ECDSASECP256K1PublicKey extends BufferStorage implements PublicKeyStorage {
|
|
58
|
+
static isInstance: (obj: any, strict?: boolean) => obj is ECDSASECP256K1PublicKey;
|
|
59
|
+
constructor(key: InputKeyTypes);
|
|
60
|
+
get ASN1(): BufferStorageASN1<publicKeyASN1, undefined>;
|
|
61
|
+
}
|
|
62
|
+
declare class ECDSASECP256R1PrivateKey extends KeyStorage {
|
|
63
|
+
static isInstance: (obj: any, strict?: boolean) => obj is ECDSASECP256R1PrivateKey;
|
|
64
|
+
}
|
|
65
|
+
declare class ECDSASECP256R1PublicKey extends BufferStorage implements PublicKeyStorage {
|
|
66
|
+
static isInstance: (obj: any, strict?: boolean) => obj is ECDSASECP256R1PublicKey;
|
|
67
|
+
constructor(key: InputKeyTypes);
|
|
68
|
+
get ASN1(): BufferStorageASN1<publicKeyASN1, undefined>;
|
|
69
|
+
}
|
|
70
|
+
declare class ED25519PrivateKey extends KeyStorage {
|
|
71
|
+
static isInstance: (obj: any, strict?: boolean) => obj is ED25519PrivateKey;
|
|
72
|
+
}
|
|
73
|
+
declare class ED25519PublicKey extends KeyStorage implements PublicKeyStorage {
|
|
74
|
+
static isInstance: (obj: any, strict?: boolean) => obj is ED25519PublicKey;
|
|
75
|
+
get ASN1(): BufferStorageASN1<publicKeyASN1, undefined>;
|
|
76
|
+
}
|
|
77
|
+
declare class IdentifierKey extends KeyStorage implements PublicKeyStorage {
|
|
78
|
+
static isInstance: (obj: any, strict?: boolean) => obj is IdentifierKey;
|
|
79
|
+
get ASN1(): never;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Signatures in ED25519 and ECDSA SECP256K1 and R1 are 512-bits long
|
|
83
|
+
*/
|
|
84
|
+
declare class SignatureStorage extends BufferStorage {
|
|
85
|
+
static isInstance: (obj: any, strict?: boolean) => obj is SignatureStorage;
|
|
86
|
+
constructor(signature: InputKeyTypes);
|
|
87
|
+
}
|
|
88
|
+
declare class ECDSASECP256K1Signature extends SignatureStorage {
|
|
89
|
+
static isInstance: (obj: any, strict?: boolean) => obj is ECDSASECP256K1Signature;
|
|
90
|
+
}
|
|
91
|
+
declare class ECDSASECP256R1Signature extends SignatureStorage {
|
|
92
|
+
static isInstance: (obj: any, strict?: boolean) => obj is ECDSASECP256R1Signature;
|
|
93
|
+
}
|
|
94
|
+
declare class ED25519Signature extends SignatureStorage {
|
|
95
|
+
static isInstance: (obj: any, strict?: boolean) => obj is ED25519Signature;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* A "public key string" is a base32-encoded string with a prefix and checksum
|
|
99
|
+
* that contains the public key plus the algorithm information
|
|
100
|
+
*/
|
|
101
|
+
declare class PublicKeyString<T extends AccountKeyAlgorithm = AccountKeyAlgorithm> {
|
|
102
|
+
#private;
|
|
103
|
+
static isInstance: (obj: any, strict?: boolean) => obj is PublicKeyString<AccountKeyAlgorithm>;
|
|
104
|
+
constructor(publicKeyString: string);
|
|
105
|
+
get publicKeyPair(): ECDSASECP256K1KeyPair | ECDSASECP256R1KeyPair | ED25519KeyPair | IdentifierKeyPair;
|
|
106
|
+
get(): PublicKeyStringMapping[T];
|
|
107
|
+
toString(): PublicKeyStringMapping[T];
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Options for signing and verifying
|
|
111
|
+
*/
|
|
112
|
+
interface signOptionsType {
|
|
113
|
+
/**
|
|
114
|
+
* Perform signing or verification on the raw data ?
|
|
115
|
+
*
|
|
116
|
+
* The default is false (meaning the data will get hashed before signed)
|
|
117
|
+
*/
|
|
118
|
+
raw?: boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Is this signing or verification for an X.509 certificate ?
|
|
121
|
+
* The format can be different between our native format and what
|
|
122
|
+
* is accept for X.509
|
|
123
|
+
*/
|
|
124
|
+
forCert?: boolean;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Signing function, accepts arbitrary data and returns a detached signature
|
|
128
|
+
*/
|
|
129
|
+
type signFunctionType = (data: ArrayBuffer, options?: signOptionsType) => Promise<ECDSASECP256K1Signature | ECDSASECP256R1Signature | ED25519Signature | BufferStorage>;
|
|
130
|
+
/**
|
|
131
|
+
* Encryption function, accepts arbitrary data and returns an encrypted buffer
|
|
132
|
+
*/
|
|
133
|
+
type encryptFunctionType = (data: ArrayBuffer) => Promise<ArrayBuffer>;
|
|
134
|
+
/**
|
|
135
|
+
* Decryption function, accepts arbitrary data and returns a decrypted buffer
|
|
136
|
+
*/
|
|
137
|
+
type decryptFunctionType = (data: ArrayBuffer) => Promise<ArrayBuffer>;
|
|
138
|
+
/**
|
|
139
|
+
* Verification function, accepts data and a detached signature and returns a result.
|
|
140
|
+
*/
|
|
141
|
+
type verifyFunctionType = (data: ArrayBuffer, signature: ECDSASECP256K1Signature | ECDSASECP256R1Signature | ED25519Signature | BufferStorage | ArrayBuffer, options?: signOptionsType) => boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Key derivation from seed+index
|
|
144
|
+
*/
|
|
145
|
+
type seedDerivationFunction = (seed: ArrayBuffer | string, index: number) => ECDSASECP256K1PrivateKey | ECDSASECP256R1PrivateKey | ED25519PublicKey | IdentifierKeyPair;
|
|
146
|
+
/**
|
|
147
|
+
* Construct new instance from seed+index
|
|
148
|
+
*/
|
|
149
|
+
type fromSeedFunctionType = (seed: ArrayBuffer | string, index: number) => IdentifierKeyPair | ED25519KeyPair | ECDSASECP256K1KeyPair | ECDSASECP256R1KeyPair;
|
|
150
|
+
/**
|
|
151
|
+
* Abstract interface to all kinds of key-related functions
|
|
152
|
+
*/
|
|
153
|
+
declare abstract class KeyInterface {
|
|
154
|
+
/**
|
|
155
|
+
* Create a private key generated from a seed value and an index
|
|
156
|
+
*/
|
|
157
|
+
static derivePrivateKeyFromSeed?: seedDerivationFunction;
|
|
158
|
+
/**
|
|
159
|
+
* Create a new instance with a private key generated from a seed value and index
|
|
160
|
+
*/
|
|
161
|
+
static fromSeed?: fromSeedFunctionType;
|
|
162
|
+
/**
|
|
163
|
+
* Sign some data
|
|
164
|
+
*/
|
|
165
|
+
abstract sign(...parameters: Parameters<signFunctionType>): ReturnType<signFunctionType>;
|
|
166
|
+
/**
|
|
167
|
+
* Verify a signature
|
|
168
|
+
*/
|
|
169
|
+
abstract verify(...parameters: Parameters<verifyFunctionType>): ReturnType<verifyFunctionType>;
|
|
170
|
+
/**
|
|
171
|
+
* Encrypt some data
|
|
172
|
+
*/
|
|
173
|
+
abstract encrypt(...parameters: Parameters<encryptFunctionType>): ReturnType<encryptFunctionType>;
|
|
174
|
+
/**
|
|
175
|
+
* Decrypt some data
|
|
176
|
+
*/
|
|
177
|
+
abstract decrypt(...parameters: Parameters<decryptFunctionType>): ReturnType<decryptFunctionType>;
|
|
178
|
+
/**
|
|
179
|
+
* Determine if the key supports encryption/decryption
|
|
180
|
+
*/
|
|
181
|
+
readonly abstract supportsEncryption: boolean;
|
|
182
|
+
/**
|
|
183
|
+
* Get the type of key in use (ECDSA or ED25519) for this key pair
|
|
184
|
+
*/
|
|
185
|
+
readonly abstract keyType: AccountKeyAlgorithm;
|
|
186
|
+
/**
|
|
187
|
+
* Get the public key for this key pair
|
|
188
|
+
*/
|
|
189
|
+
readonly abstract publicKey: ECDSASECP256K1PublicKey | ECDSASECP256R1PublicKey | ED25519PublicKey;
|
|
190
|
+
/**
|
|
191
|
+
* Determine if this key pair has a private key associated
|
|
192
|
+
*/
|
|
193
|
+
readonly abstract hasPrivateKey: boolean;
|
|
194
|
+
/**
|
|
195
|
+
* Testing interface to validate that a private key is equal to some
|
|
196
|
+
* value (undefined if undecidable)
|
|
197
|
+
*/
|
|
198
|
+
abstract _checkPrivateKey(checkKey: ArrayBuffer): boolean | undefined;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* External key pairs allow arbitrary external keying mechanisms (such as
|
|
202
|
+
* PKCS#11) to be used to back accounts
|
|
203
|
+
*/
|
|
204
|
+
interface BaseExternalKeyPairFunctions {
|
|
205
|
+
sign: signFunctionType;
|
|
206
|
+
verify?: verifyFunctionType;
|
|
207
|
+
supportsEncryption: boolean;
|
|
208
|
+
}
|
|
209
|
+
interface ExternalKeyPairFunctionsSupportsEncryption extends BaseExternalKeyPairFunctions {
|
|
210
|
+
supportsEncryption: true;
|
|
211
|
+
encrypt?: encryptFunctionType;
|
|
212
|
+
decrypt: decryptFunctionType;
|
|
213
|
+
}
|
|
214
|
+
interface ExternalKeyPairFunctionsNoEncryption extends BaseExternalKeyPairFunctions {
|
|
215
|
+
supportsEncryption: false;
|
|
216
|
+
}
|
|
217
|
+
type ExternalKeyPairFunctions = ExternalKeyPairFunctionsSupportsEncryption | ExternalKeyPairFunctionsNoEncryption;
|
|
218
|
+
export declare class ExternalKeyPair extends KeyInterface {
|
|
219
|
+
#private;
|
|
220
|
+
readonly driverHandlesHashing: boolean;
|
|
221
|
+
static isInstance: (obj: any, strict?: boolean) => obj is ExternalKeyPair;
|
|
222
|
+
constructor(functions: ExternalKeyPairFunctions, publicKey: ArrayBuffer | string, keyType: AccountKeyAlgorithm, driverHandlesHashing?: boolean);
|
|
223
|
+
sign(...parameters: Parameters<signFunctionType>): ReturnType<signFunctionType>;
|
|
224
|
+
verify(data: Parameters<verifyFunctionType>[0], signature: Parameters<verifyFunctionType>[1], options: Parameters<verifyFunctionType>[2]): ReturnType<verifyFunctionType>;
|
|
225
|
+
encrypt(...parameters: Parameters<encryptFunctionType>): ReturnType<encryptFunctionType>;
|
|
226
|
+
decrypt(...parameters: Parameters<decryptFunctionType>): ReturnType<decryptFunctionType>;
|
|
227
|
+
get supportsEncryption(): boolean;
|
|
228
|
+
get keyType(): AccountKeyAlgorithm;
|
|
229
|
+
get publicKey(): ECDSASECP256K1PublicKey | ECDSASECP256R1PublicKey | ED25519PublicKey;
|
|
230
|
+
get hasPrivateKey(): boolean;
|
|
231
|
+
_checkPrivateKey(_ignore_checkKey: ArrayBuffer): undefined;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Generic ECDSA Key interface
|
|
235
|
+
*/
|
|
236
|
+
declare abstract class ECDSAKeyPair extends KeyInterface {
|
|
237
|
+
readonly supportsEncryption = true;
|
|
238
|
+
/**
|
|
239
|
+
* Construct an SEC-like signature from a DER encoded ECDSA [R,S] structure
|
|
240
|
+
*/
|
|
241
|
+
protected static signatureFromDERRaw(values: number[]): Uint8Array;
|
|
242
|
+
/**
|
|
243
|
+
* Construct an ASN.1-encoded [R,S] struct from the SEC-like value
|
|
244
|
+
*/
|
|
245
|
+
protected static signatureToDER(signature: ECDSASECP256K1Signature | ECDSASECP256R1Signature): number[];
|
|
246
|
+
}
|
|
247
|
+
declare class ECDSASECP256K1KeyPair extends ECDSAKeyPair {
|
|
248
|
+
#private;
|
|
249
|
+
static derivePrivateKeyFromSeed(seed: ArrayBuffer | string, index: number): ECDSASECP256K1PrivateKey;
|
|
250
|
+
static fromSeed(seed: ArrayBuffer | string, index: number): ECDSASECP256K1KeyPair;
|
|
251
|
+
static derivePublicKeyFromPrivateKey(key: ECDSASECP256K1PrivateKey): ECDSASECP256K1PublicKey;
|
|
252
|
+
static signatureFromDER(signature: number[]): ECDSASECP256K1Signature;
|
|
253
|
+
static signatureToDER(signature: ECDSASECP256K1Signature): number[];
|
|
254
|
+
static isInstance: (obj: any, strict?: boolean) => obj is ECDSASECP256K1KeyPair;
|
|
255
|
+
constructor(privateKey?: ECDSASECP256K1PrivateKey | ArrayBuffer | string, publicKey?: ECDSASECP256K1PublicKey | ArrayBuffer | string);
|
|
256
|
+
sign(data: ArrayBuffer, options?: signOptionsType): Promise<ECDSASECP256K1Signature | BufferStorage>;
|
|
257
|
+
verify(data: ArrayBuffer, signature: ECDSASECP256K1Signature | BufferStorage | ArrayBuffer, options?: signOptionsType): boolean;
|
|
258
|
+
encrypt(data: ArrayBuffer): Promise<ArrayBuffer>;
|
|
259
|
+
decrypt(data: ArrayBuffer): Promise<ArrayBuffer>;
|
|
260
|
+
get keyType(): AccountKeyAlgorithm;
|
|
261
|
+
get publicKey(): ECDSASECP256K1PublicKey;
|
|
262
|
+
get hasPrivateKey(): boolean;
|
|
263
|
+
_checkPrivateKey(checkKey: ArrayBuffer): boolean | undefined;
|
|
264
|
+
}
|
|
265
|
+
declare class ECDSASECP256R1KeyPair extends ECDSAKeyPair {
|
|
266
|
+
#private;
|
|
267
|
+
static derivePrivateKeyFromSeed(seed: ArrayBuffer | string, index: number): ECDSASECP256R1PrivateKey;
|
|
268
|
+
static fromSeed(seed: ArrayBuffer | string, index: number): ECDSASECP256R1KeyPair;
|
|
269
|
+
static derivePublicKeyFromPrivateKey(key: ECDSASECP256R1PrivateKey): ECDSASECP256R1PublicKey;
|
|
270
|
+
/**
|
|
271
|
+
* Construct an SEC-like signature from a DER encoded ECDSA [R,S] structure
|
|
272
|
+
*/
|
|
273
|
+
static signatureFromDER(signature: number[]): ECDSASECP256R1Signature;
|
|
274
|
+
/**
|
|
275
|
+
* Construct an ASN.1-encoded [R,S] struct from the SEC-like value
|
|
276
|
+
*/
|
|
277
|
+
static signatureToDER(signature: ECDSASECP256R1Signature): number[];
|
|
278
|
+
static isInstance: (obj: any, strict?: boolean) => obj is ECDSASECP256R1KeyPair;
|
|
279
|
+
constructor(privateKey?: ECDSASECP256R1PrivateKey | ArrayBuffer | string, publicKey?: ECDSASECP256R1PublicKey | ArrayBuffer | string);
|
|
280
|
+
sign(data: ArrayBuffer, options?: signOptionsType): Promise<ECDSASECP256R1Signature | BufferStorage>;
|
|
281
|
+
verify(data: ArrayBuffer, signature: ECDSASECP256R1Signature | BufferStorage | ArrayBuffer, options?: signOptionsType): boolean;
|
|
282
|
+
encrypt(data: ArrayBuffer): Promise<ArrayBuffer>;
|
|
283
|
+
decrypt(data: ArrayBuffer): Promise<ArrayBuffer>;
|
|
284
|
+
get keyType(): AccountKeyAlgorithm;
|
|
285
|
+
get publicKey(): ECDSASECP256R1PublicKey;
|
|
286
|
+
get hasPrivateKey(): boolean;
|
|
287
|
+
_checkPrivateKey(checkKey: ArrayBuffer): boolean | undefined;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* ED25519 Key Interface
|
|
291
|
+
*/
|
|
292
|
+
declare class ED25519KeyPair extends KeyInterface {
|
|
293
|
+
#private;
|
|
294
|
+
readonly supportsEncryption = true;
|
|
295
|
+
static derivePrivateKeyFromSeed(seed: ArrayBuffer | string, index: number): ED25519PrivateKey;
|
|
296
|
+
static fromSeed(seed: ArrayBuffer | string, index: number): ED25519KeyPair;
|
|
297
|
+
static derivePublicKeyFromPrivateKey(key: ED25519PrivateKey): ED25519PublicKey;
|
|
298
|
+
static isInstance: (obj: any, strict?: boolean) => obj is ED25519KeyPair;
|
|
299
|
+
constructor(privateKey?: ED25519PrivateKey | ArrayBuffer | string, publicKey?: ED25519PublicKey | ArrayBuffer | string);
|
|
300
|
+
sign(data: ArrayBuffer): Promise<ED25519Signature>;
|
|
301
|
+
verify(data: ArrayBuffer, signature: ED25519Signature | BufferStorage | ArrayBuffer): boolean;
|
|
302
|
+
encrypt(data: ArrayBuffer): Promise<ArrayBuffer>;
|
|
303
|
+
decrypt(data: ArrayBuffer): Promise<ArrayBuffer>;
|
|
304
|
+
get keyType(): AccountKeyAlgorithm;
|
|
305
|
+
get publicKey(): ED25519PublicKey;
|
|
306
|
+
get hasPrivateKey(): boolean;
|
|
307
|
+
_checkPrivateKey(checkKey: ArrayBuffer): boolean | undefined;
|
|
308
|
+
}
|
|
309
|
+
declare class IdentifierKeyPair extends KeyInterface {
|
|
310
|
+
#private;
|
|
311
|
+
static isInstance: (obj: any, strict?: boolean) => obj is IdentifierKeyPair;
|
|
312
|
+
readonly supportsEncryption = false;
|
|
313
|
+
static derivePrivateKeyFromSeed(seed: ArrayBuffer | string, index: number): IdentifierKey;
|
|
314
|
+
static derivePublicKeyFromPrivateKey(key: IdentifierKey): IdentifierKey;
|
|
315
|
+
constructor(key: IdentifierKey | ArrayBuffer | string, identifierType: IdentifierKeyAlgorithm);
|
|
316
|
+
sign(_ignored_data: ArrayBuffer): Promise<BufferStorage>;
|
|
317
|
+
verify(_ignored_data: ArrayBuffer, _ignored_signature: ED25519Signature | ArrayBuffer): boolean;
|
|
318
|
+
get publicKey(): IdentifierKey;
|
|
319
|
+
get hasPrivateKey(): boolean;
|
|
320
|
+
get keyType(): AccountKeyAlgorithm;
|
|
321
|
+
static fromSeed(seed: ArrayBuffer | string, index: number, type?: AccountKeyAlgorithm & IdentifierKeyAlgorithm): IdentifierKeyPair;
|
|
322
|
+
_checkPrivateKey(_ignored_checkKey: ArrayBuffer): boolean | undefined;
|
|
323
|
+
encrypt(..._ignored_parameters: Parameters<encryptFunctionType>): ReturnType<encryptFunctionType>;
|
|
324
|
+
decrypt(..._ignored_parameters: Parameters<decryptFunctionType>): ReturnType<decryptFunctionType>;
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Key pair types which we can process
|
|
328
|
+
*/
|
|
329
|
+
type KeyPairTypes = ECDSAKeyPair | ECDSASECP256K1KeyPair | ECDSASECP256R1KeyPair | ED25519KeyPair | IdentifierKeyPair | ExternalKeyPair;
|
|
330
|
+
/**
|
|
331
|
+
* Generic interface to an account. An account may be backed by a private key
|
|
332
|
+
* (in which case it can sign data), a seed+index (which is used to generate
|
|
333
|
+
* a private key), or a public key (which can only verify blocks).
|
|
334
|
+
*/
|
|
335
|
+
type PublicKeyStringPrefixed<X extends string> = `${AccountPrefix}${X}${string}`;
|
|
336
|
+
export type Secp256K1PublicKeyString = PublicKeyStringPrefixed<'aa' | 'ab' | 'ac' | 'ad'>;
|
|
337
|
+
export type Secp256R1PublicKeyString = PublicKeyStringPrefixed<'ay' | 'az' | 'a2' | 'a3'>;
|
|
338
|
+
export type ED25519PublicKeyString = PublicKeyStringPrefixed<'ae' | 'af' | 'ag' | 'ah'>;
|
|
339
|
+
export type NetworkPublicKeyString = PublicKeyStringPrefixed<'ai' | 'aj' | 'ak' | 'al'>;
|
|
340
|
+
export type TokenPublicKeyString = PublicKeyStringPrefixed<'am' | 'an' | 'ao' | 'ap'>;
|
|
341
|
+
export type StoragePublicKeyString = PublicKeyStringPrefixed<'aq' | 'ar' | 'as' | 'at'>;
|
|
342
|
+
export interface PublicKeyStringMapping {
|
|
343
|
+
[AccountKeyAlgorithm.ECDSA_SECP256K1]: Secp256K1PublicKeyString;
|
|
344
|
+
[AccountKeyAlgorithm.ECDSA_SECP256R1]: Secp256R1PublicKeyString;
|
|
345
|
+
[AccountKeyAlgorithm.ED25519]: ED25519PublicKeyString;
|
|
346
|
+
[AccountKeyAlgorithm.TOKEN]: TokenPublicKeyString;
|
|
347
|
+
[AccountKeyAlgorithm.NETWORK]: NetworkPublicKeyString;
|
|
348
|
+
[AccountKeyAlgorithm.STORAGE]: StoragePublicKeyString;
|
|
349
|
+
}
|
|
350
|
+
export type IdentifierPublicKeyString = PublicKeyStringMapping[IdentifierKeyAlgorithm];
|
|
351
|
+
export type AccountPublicKeyString = Secp256K1PublicKeyString | Secp256R1PublicKeyString | ED25519PublicKeyString;
|
|
352
|
+
export declare class Account<T extends AccountKeyAlgorithm = Exclude<AccountKeyAlgorithm, IdentifierKeyAlgorithm>> {
|
|
353
|
+
#private;
|
|
354
|
+
static AccountKeyAlgorithm: typeof AccountKeyAlgorithm;
|
|
355
|
+
static ExternalKeyPair: typeof ExternalKeyPair;
|
|
356
|
+
/**
|
|
357
|
+
* Construct an account from a public key string. The public key
|
|
358
|
+
* string encodes the type and public key data
|
|
359
|
+
*/
|
|
360
|
+
static fromPublicKeyString(key: TokenPublicKeyString): Account<AccountKeyAlgorithm.TOKEN>;
|
|
361
|
+
static fromPublicKeyString(key: NetworkPublicKeyString): Account<AccountKeyAlgorithm.NETWORK>;
|
|
362
|
+
static fromPublicKeyString(key: StoragePublicKeyString): Account<AccountKeyAlgorithm.STORAGE>;
|
|
363
|
+
static fromPublicKeyString(key: Secp256K1PublicKeyString): Account<AccountKeyAlgorithm.ECDSA_SECP256K1>;
|
|
364
|
+
static fromPublicKeyString(key: Secp256R1PublicKeyString): Account<AccountKeyAlgorithm.ECDSA_SECP256R1>;
|
|
365
|
+
static fromPublicKeyString(key: ED25519PublicKeyString): Account<AccountKeyAlgorithm.ED25519>;
|
|
366
|
+
static fromPublicKeyString(key: IdentifierPublicKeyString): Account<IdentifierKeyAlgorithm>;
|
|
367
|
+
static fromPublicKeyString(key: AccountPublicKeyString): Account;
|
|
368
|
+
static fromPublicKeyString(key: string): GenericAccount;
|
|
369
|
+
/**
|
|
370
|
+
* Construct an account from an ECDSA private key for SECP256K1.
|
|
371
|
+
*/
|
|
372
|
+
static fromECDSASECP256K1PrivateKey(key: InputKeyTypes): Account<AccountKeyAlgorithm.ECDSA_SECP256K1>;
|
|
373
|
+
/**
|
|
374
|
+
* Construct an account from an ECDSA private key for SECP256R1.
|
|
375
|
+
*/
|
|
376
|
+
static fromECDSASECP256R1PrivateKey(key: InputKeyTypes): Account<AccountKeyAlgorithm.ECDSA_SECP256R1>;
|
|
377
|
+
/**
|
|
378
|
+
* Construct an account from an ED25519 private key.
|
|
379
|
+
*/
|
|
380
|
+
static fromED25519PrivateKey(key: InputKeyTypes): Account<AccountKeyAlgorithm.ED25519>;
|
|
381
|
+
/**
|
|
382
|
+
* Construct an account from an ECDSA public key for SECP256K1.
|
|
383
|
+
*/
|
|
384
|
+
static fromECDSASECP256K1PublicKey(key: InputKeyTypes): Account<AccountKeyAlgorithm.ECDSA_SECP256K1>;
|
|
385
|
+
/**
|
|
386
|
+
* Construct an account from an ECDSA public key for SECP256R1.
|
|
387
|
+
*/
|
|
388
|
+
static fromECDSASECP256R1PublicKey(key: InputKeyTypes): Account<AccountKeyAlgorithm.ECDSA_SECP256R1>;
|
|
389
|
+
/**
|
|
390
|
+
* Construct an identifier account from the input key and the identifier algo
|
|
391
|
+
*/
|
|
392
|
+
protected static fromIdentifierPublicKey<Type extends IdentifierKeyAlgorithm>(key: InputKeyTypes, type: Type): Account<Type>;
|
|
393
|
+
/**
|
|
394
|
+
* Construct an account from a network identifier public key
|
|
395
|
+
*/
|
|
396
|
+
static fromNetworkPublicKey(key: InputKeyTypes): Account<AccountKeyAlgorithm.NETWORK>;
|
|
397
|
+
/**
|
|
398
|
+
* Construct an account from a token identifier public key
|
|
399
|
+
*/
|
|
400
|
+
static fromTokenPublicKey(key: InputKeyTypes): Account<AccountKeyAlgorithm.TOKEN>;
|
|
401
|
+
/**
|
|
402
|
+
* Construct an account from a storage identifier public key
|
|
403
|
+
*/
|
|
404
|
+
static fromStoragePublicKey(key: InputKeyTypes): Account<AccountKeyAlgorithm.STORAGE>;
|
|
405
|
+
/**
|
|
406
|
+
* Construct an account from an ED25519 public key.
|
|
407
|
+
*/
|
|
408
|
+
static fromED25519PublicKey(key: InputKeyTypes): Account<AccountKeyAlgorithm.ED25519>;
|
|
409
|
+
/**
|
|
410
|
+
* Construct an Account from an KeyType and Public Key buffer
|
|
411
|
+
*/
|
|
412
|
+
static fromPublicKeyAndType(keyData: Buffer): GenericAccount;
|
|
413
|
+
/**
|
|
414
|
+
* Construct a new account from a public key encoded in DER-encoded ASN.1
|
|
415
|
+
*/
|
|
416
|
+
static fromASN1(asn1: ArrayBuffer | publicKeyASN1): Account;
|
|
417
|
+
/**
|
|
418
|
+
* Construct an account from a Seed and Index.
|
|
419
|
+
*/
|
|
420
|
+
static fromSeed<Z extends AccountKeyAlgorithm>(seed: ArrayBuffer | string | bigint, index: number, keyType: Z): Account<Z>;
|
|
421
|
+
static fromSeed(seed: ArrayBuffer | string | bigint, index: number): Account<AccountKeyAlgorithm.ECDSA_SECP256K1>;
|
|
422
|
+
static generateNetworkAddress(networkId: bigint): NetworkAddress;
|
|
423
|
+
static generateBaseAddresses(networkId: bigint): {
|
|
424
|
+
networkAddress: NetworkAddress;
|
|
425
|
+
baseToken: TokenAddress;
|
|
426
|
+
};
|
|
427
|
+
/**
|
|
428
|
+
* Securely generate a new random seed value
|
|
429
|
+
*/
|
|
430
|
+
static generateRandomSeed(options: {
|
|
431
|
+
asString: true;
|
|
432
|
+
}): string;
|
|
433
|
+
static generateRandomSeed(options: {
|
|
434
|
+
asString: false;
|
|
435
|
+
}): ArrayBuffer;
|
|
436
|
+
static generateRandomSeed(): ArrayBuffer;
|
|
437
|
+
static generateRandomSeed(options?: {
|
|
438
|
+
asString: boolean;
|
|
439
|
+
}): ArrayBuffer | string;
|
|
440
|
+
/**
|
|
441
|
+
* Convert a passphrase into a seed
|
|
442
|
+
*/
|
|
443
|
+
static seedFromPassphrase(passphrase: string, options: {
|
|
444
|
+
asString: true;
|
|
445
|
+
}): Promise<string>;
|
|
446
|
+
static seedFromPassphrase(passphrase: string, options: {
|
|
447
|
+
asString: false;
|
|
448
|
+
}): Promise<ArrayBuffer>;
|
|
449
|
+
static seedFromPassphrase(passphrase: string): Promise<ArrayBuffer>;
|
|
450
|
+
static seedFromPassphrase(passphrase: string, options?: {
|
|
451
|
+
asString: boolean;
|
|
452
|
+
}): Promise<ArrayBuffer | string>;
|
|
453
|
+
static toAccount(): undefined;
|
|
454
|
+
static toAccount(acct: null): null;
|
|
455
|
+
static toAccount(acct: undefined): undefined;
|
|
456
|
+
static toAccount<toAlgo extends AccountKeyAlgorithm>(acct: string | Account<toAlgo>): Account<toAlgo>;
|
|
457
|
+
static toAccount<toAlgo extends AccountKeyAlgorithm>(acct: string | Account<toAlgo> | null): Account<toAlgo> | null;
|
|
458
|
+
static toAccount<toAlgo extends AccountKeyAlgorithm>(acct: string | Account<toAlgo> | undefined): Account<toAlgo> | undefined;
|
|
459
|
+
static toAccount<X extends AccountKeyAlgorithm>(acct: string | Account<X> | undefined | null): Account<X> | undefined | null;
|
|
460
|
+
static toPublicKeyString(): undefined;
|
|
461
|
+
static toPublicKeyString(acct: Account<AccountKeyAlgorithm>): string;
|
|
462
|
+
static toPublicKeyString(acct: null): null;
|
|
463
|
+
static toPublicKeyString(acct: undefined): undefined;
|
|
464
|
+
static toPublicKeyString(acct: undefined | Account<AccountKeyAlgorithm>): string | undefined;
|
|
465
|
+
static toPublicKeyString(acct: string | Account<AccountKeyAlgorithm>): string;
|
|
466
|
+
static toPublicKeyString(acct: string | Account<AccountKeyAlgorithm> | null): string | null;
|
|
467
|
+
static toPublicKeyString(acct: string | Account<AccountKeyAlgorithm> | undefined): string | undefined;
|
|
468
|
+
static toPublicKeyString(acct: string | Account<AccountKeyAlgorithm> | undefined | null): string | undefined | null;
|
|
469
|
+
static comparePublicKeys(acct1: Account<AccountKeyAlgorithm> | string | undefined | null, acct2: Account<AccountKeyAlgorithm> | string | undefined | null): boolean;
|
|
470
|
+
static isInstance: (obj: any, strict?: boolean) => obj is Account<AccountKeyAlgorithm>;
|
|
471
|
+
static Set: import("./utils/helper").InstanceSetConstructor<Account<AccountKeyAlgorithm>, string>;
|
|
472
|
+
constructor(key: KeyPairTypes | ECDSASECP256K1PrivateKey | ECDSASECP256R1PrivateKey | ED25519PrivateKey | ECDSASECP256K1PublicKey | ECDSASECP256R1PublicKey | ED25519PublicKey | IdentifierKeyPair | IdentifierKey | PublicKeyString | Account<T>, requiredKeyType?: T);
|
|
473
|
+
/**
|
|
474
|
+
* Sign some data and generate a detached signature in SEC format
|
|
475
|
+
*/
|
|
476
|
+
sign(data: ArrayBuffer, options?: signOptionsType): ReturnType<signFunctionType>;
|
|
477
|
+
/**
|
|
478
|
+
* Verify a detached signature against some data
|
|
479
|
+
*/
|
|
480
|
+
verify(data: ArrayBuffer, signature: ArrayBuffer | BufferStorage | ECDSASECP256K1Signature | ECDSASECP256R1Signature | ED25519Signature, options?: signOptionsType): ReturnType<verifyFunctionType>;
|
|
481
|
+
encrypt(data: ArrayBuffer): ReturnType<encryptFunctionType>;
|
|
482
|
+
decrypt(data: ArrayBuffer): ReturnType<decryptFunctionType>;
|
|
483
|
+
get supportsEncryption(): boolean;
|
|
484
|
+
/**
|
|
485
|
+
* Internal helper method to copy accounts
|
|
486
|
+
*/
|
|
487
|
+
_getPrivateKey(): KeyPairTypes | null;
|
|
488
|
+
/**
|
|
489
|
+
* Internal helper method to copy accounts
|
|
490
|
+
*/
|
|
491
|
+
_getPublicKey(): KeyPairTypes;
|
|
492
|
+
comparePublicKey(acct: Account<AccountKeyAlgorithm> | string | undefined | null): boolean;
|
|
493
|
+
/**
|
|
494
|
+
* Get token relative to account blockOrder and operationIndex
|
|
495
|
+
*/
|
|
496
|
+
generateIdentifier<Type extends IdentifierKeyAlgorithm>(type: Type, blockHash: BlockHash | string | undefined, operationIndex: number): Account<Type>;
|
|
497
|
+
/**
|
|
498
|
+
* Get the encoded public key string
|
|
499
|
+
*/
|
|
500
|
+
get publicKeyString(): PublicKeyString<T>;
|
|
501
|
+
/**
|
|
502
|
+
* Get the type of key for this account (SECP256K1 / R1 or ED25519)
|
|
503
|
+
*/
|
|
504
|
+
get keyType(): T;
|
|
505
|
+
/**
|
|
506
|
+
* Get the public key for this account
|
|
507
|
+
*/
|
|
508
|
+
get publicKey(): ECDSASECP256K1PublicKey | ECDSASECP256R1PublicKey | ED25519PublicKey;
|
|
509
|
+
get publicKeyAndType(): Buffer;
|
|
510
|
+
/**
|
|
511
|
+
* Determine if this account has a private key associated with it
|
|
512
|
+
*/
|
|
513
|
+
get hasPrivateKey(): boolean;
|
|
514
|
+
/**
|
|
515
|
+
* Determine the size of signatures (in bytes) or null if the key
|
|
516
|
+
* type cannot produce signatures
|
|
517
|
+
*/
|
|
518
|
+
get signatureSize(): number | null;
|
|
519
|
+
/**
|
|
520
|
+
* Determine if a key type is an identifier key type
|
|
521
|
+
*/
|
|
522
|
+
static isIdentifierKeyType(keyType: any): keyType is IdentifierKeyAlgorithm;
|
|
523
|
+
/**
|
|
524
|
+
* Determine if an account is an identifier
|
|
525
|
+
*/
|
|
526
|
+
isIdentifier(): this is IdentifierAddress;
|
|
527
|
+
isAccount(): this is Account;
|
|
528
|
+
isKeyType<CheckType extends AccountKeyAlgorithm>(checkKeyType: CheckType): this is Account<CheckType>;
|
|
529
|
+
isStorage(): this is Account<AccountKeyAlgorithm.STORAGE>;
|
|
530
|
+
isNetwork(): this is Account<AccountKeyAlgorithm.NETWORK>;
|
|
531
|
+
isToken(): this is Account<AccountKeyAlgorithm.TOKEN>;
|
|
532
|
+
assertKeyType<KeyType extends AccountKeyAlgorithm>(keyType: KeyType): Account<KeyType>;
|
|
533
|
+
assertAccount(): Account;
|
|
534
|
+
assertIdentifier(): IdentifierAddress;
|
|
535
|
+
static toJSONSerializablePrefix: string;
|
|
536
|
+
static toJSONSerializable(value: GenericAccount): Secp256K1PublicKeyString | ED25519PublicKeyString | NetworkPublicKeyString | TokenPublicKeyString | StoragePublicKeyString | Secp256R1PublicKeyString;
|
|
537
|
+
}
|
|
538
|
+
export type TokenAddress = Account<AccountKeyAlgorithm.TOKEN>;
|
|
539
|
+
export type StorageAddress = Account<AccountKeyAlgorithm.STORAGE>;
|
|
540
|
+
export type NetworkAddress = Account<AccountKeyAlgorithm.NETWORK>;
|
|
541
|
+
export type IdentifierAddress = Account<IdentifierKeyAlgorithm>;
|
|
542
|
+
export type NonIdentifierAccount = Account<Exclude<AccountKeyAlgorithm, IdentifierKeyAlgorithm>>;
|
|
543
|
+
export type GenericAccount = Account<AccountKeyAlgorithm>;
|
|
544
|
+
export default Account;
|