@ocap/sdk 1.16.15 → 1.17.0
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/index.d.ts +284 -180
- package/package.json +7 -7
package/index.d.ts
CHANGED
|
@@ -1,4 +1,209 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import rightPad from 'lodash/padEnd';
|
|
3
|
+
import leftPad from 'lodash/padStart';
|
|
4
|
+
import BN from 'bn.js';
|
|
5
|
+
export declare type BytesType = string | Buffer | Uint8Array;
|
|
6
|
+
export declare type EncodingType = 'hex' | 'base16' | 'base58' | 'base64' | 'Uint8Array' | 'buffer';
|
|
7
|
+
export declare type KeyPairType = {
|
|
8
|
+
publicKey: BytesType;
|
|
9
|
+
secretKey: BytesType;
|
|
10
|
+
};
|
|
11
|
+
export { BN, leftPad, rightPad };
|
|
12
|
+
/**
|
|
13
|
+
* Returns a BN object, converts a number value to a BN
|
|
14
|
+
* @param {String|Number|Object} `arg` input a string number, hex string number, number, BigNumber or BN object
|
|
15
|
+
* @return {Object} `output` BN object of the number
|
|
16
|
+
* @throws if the argument is not an array, object that isn't a bignumber, not a string number or number
|
|
17
|
+
*/
|
|
18
|
+
export declare const numberToBN: (arg: string | number | BN) => BN;
|
|
19
|
+
/**
|
|
20
|
+
* Returns a `boolean` on whether or not the `string` starts with '0x'
|
|
21
|
+
*
|
|
22
|
+
* @public
|
|
23
|
+
* @static
|
|
24
|
+
* @param {String} str the string input value
|
|
25
|
+
* @return {Boolean} a boolean if it is or is not hex prefixed
|
|
26
|
+
* @throws if the str input is not a string
|
|
27
|
+
*/
|
|
28
|
+
export declare const isHexPrefixed: (str: string) => boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Removes '0x' from a given `String` if present
|
|
31
|
+
*
|
|
32
|
+
* @public
|
|
33
|
+
* @static
|
|
34
|
+
* @param {String} str the string value
|
|
35
|
+
* @return {String|Optional} a string by pass if necessary
|
|
36
|
+
*/
|
|
37
|
+
export declare const stripHexPrefix: (str: $TSFixMe) => any;
|
|
38
|
+
/**
|
|
39
|
+
* Returns true if object is BN, otherwise false
|
|
40
|
+
*
|
|
41
|
+
* @public
|
|
42
|
+
* @static
|
|
43
|
+
* @method isBN
|
|
44
|
+
* @param {Object} object
|
|
45
|
+
* @returns {Boolean}
|
|
46
|
+
*/
|
|
47
|
+
export declare const isBN: (object: $TSFixMe) => boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Returns true if object is BigNumber, otherwise false
|
|
50
|
+
*
|
|
51
|
+
* @public
|
|
52
|
+
* @static
|
|
53
|
+
* @method isBigNumber
|
|
54
|
+
* @param {Object} object
|
|
55
|
+
* @returns {Boolean}
|
|
56
|
+
*/
|
|
57
|
+
export declare const isBigNumber: (object: $TSFixMe) => boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Check if string is HEX, requires a 0x in front
|
|
60
|
+
*
|
|
61
|
+
* @public
|
|
62
|
+
* @static
|
|
63
|
+
* @method isHexStrict
|
|
64
|
+
* @param {String} hex to be checked
|
|
65
|
+
* @returns {Boolean}
|
|
66
|
+
*/
|
|
67
|
+
export declare const isHexStrict: (hex: string) => boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Check if string is HEX
|
|
70
|
+
*
|
|
71
|
+
* @public
|
|
72
|
+
* @static
|
|
73
|
+
* @method isHex
|
|
74
|
+
* @param {String} hex to be checked
|
|
75
|
+
* @returns {Boolean}
|
|
76
|
+
*/
|
|
77
|
+
export declare const isHex: (hex: string) => boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Takes an input and transforms it into an BN
|
|
80
|
+
*
|
|
81
|
+
* @public
|
|
82
|
+
* @static
|
|
83
|
+
* @method toBN
|
|
84
|
+
* @param {Number|String|BN} num, string, HEX string or BN
|
|
85
|
+
* @returns {BN} BN
|
|
86
|
+
*/
|
|
87
|
+
export declare const toBN: (num: number | string | BN, base?: number | 'hex') => BN;
|
|
88
|
+
/**
|
|
89
|
+
* Should be called to get hex representation (prefixed by 0x) of utf8 string
|
|
90
|
+
*
|
|
91
|
+
* @public
|
|
92
|
+
* @static
|
|
93
|
+
* @method utf8ToHex
|
|
94
|
+
* @param {String} str
|
|
95
|
+
* @returns {String} hex representation of input string
|
|
96
|
+
*/
|
|
97
|
+
export declare const utf8ToHex: (str: string) => string;
|
|
98
|
+
/**
|
|
99
|
+
* Should be called to get utf8 from it's hex representation
|
|
100
|
+
*
|
|
101
|
+
* @public
|
|
102
|
+
* @static
|
|
103
|
+
* @method hexToUtf8
|
|
104
|
+
* @param {String} hex
|
|
105
|
+
* @returns {String} ascii string representation of hex value
|
|
106
|
+
*/
|
|
107
|
+
export declare const hexToUtf8: (hex: string) => string;
|
|
108
|
+
/**
|
|
109
|
+
* Converts value to number representation
|
|
110
|
+
*
|
|
111
|
+
* @public
|
|
112
|
+
* @static
|
|
113
|
+
* @method hexToNumber
|
|
114
|
+
* @param {String|Number|BN} value
|
|
115
|
+
* @returns {Number}
|
|
116
|
+
*/
|
|
117
|
+
export declare const hexToNumber: (value: string | number | BN) => string | number | BN;
|
|
118
|
+
/**
|
|
119
|
+
* Converts value to hex representation
|
|
120
|
+
*
|
|
121
|
+
* @public
|
|
122
|
+
* @static
|
|
123
|
+
* @method numberToHex
|
|
124
|
+
* @param {String|Number|BN} value
|
|
125
|
+
* @returns {String}
|
|
126
|
+
*/
|
|
127
|
+
export declare const numberToHex: (value: $TSFixMe) => string;
|
|
128
|
+
/**
|
|
129
|
+
* Convert a byte array to a hex string
|
|
130
|
+
* Note: Implementation from crypto-js
|
|
131
|
+
*
|
|
132
|
+
* @public
|
|
133
|
+
* @static
|
|
134
|
+
* @method bytesToHex
|
|
135
|
+
* @param {Array} bytes
|
|
136
|
+
* @returns {String} the hex string
|
|
137
|
+
*/
|
|
138
|
+
export declare const bytesToHex: (bytes: $TSFixMe) => string;
|
|
139
|
+
/**
|
|
140
|
+
* Convert a hex string to a byte array
|
|
141
|
+
* Note: Implementation from crypto-js
|
|
142
|
+
*
|
|
143
|
+
* @public
|
|
144
|
+
* @static
|
|
145
|
+
* @method hexToBytes
|
|
146
|
+
* @param {String} hex
|
|
147
|
+
* @returns {Array} the byte array
|
|
148
|
+
*/
|
|
149
|
+
export declare const hexToBytes: (hex: $TSFixMe) => number[];
|
|
150
|
+
/**
|
|
151
|
+
* Auto converts any given value into it's hex representation.
|
|
152
|
+
* And even stringify objects before.
|
|
153
|
+
*
|
|
154
|
+
* @public
|
|
155
|
+
* @static
|
|
156
|
+
* @method toHex
|
|
157
|
+
* @param {String|Number|BN|Object|TypedArray|Buffer} value
|
|
158
|
+
* @param {Boolean} returnType
|
|
159
|
+
* @returns {String}
|
|
160
|
+
*/
|
|
161
|
+
export declare const toHex: (
|
|
162
|
+
value:
|
|
163
|
+
| string
|
|
164
|
+
| number
|
|
165
|
+
| boolean
|
|
166
|
+
| BN
|
|
167
|
+
| Uint8Array
|
|
168
|
+
| Buffer
|
|
169
|
+
| (
|
|
170
|
+
| number
|
|
171
|
+
| {
|
|
172
|
+
test: string;
|
|
173
|
+
}
|
|
174
|
+
)[]
|
|
175
|
+
| {
|
|
176
|
+
test: string;
|
|
177
|
+
},
|
|
178
|
+
returnType?: boolean
|
|
179
|
+
) => string;
|
|
180
|
+
export declare const numberToString: (arg: $TSFixMe) => any;
|
|
181
|
+
/**
|
|
182
|
+
* Format a big number to human readable number, such as 1_0000_0000_0000_000 => 1 Token
|
|
183
|
+
*
|
|
184
|
+
* @public
|
|
185
|
+
* @static
|
|
186
|
+
* @method fromUnitToToken
|
|
187
|
+
* @param {string|number} input
|
|
188
|
+
* @param {number} [decimal=18]
|
|
189
|
+
* @param {object} [optionsInput=undefined]
|
|
190
|
+
* @returns {string}
|
|
191
|
+
*/
|
|
192
|
+
export declare const fromUnitToToken: (
|
|
193
|
+
input: string | number | BN,
|
|
194
|
+
decimal?: number,
|
|
195
|
+
optionsInput?: $TSFixMe
|
|
196
|
+
) => string;
|
|
197
|
+
/**
|
|
198
|
+
* Convert human readable token number to big number instance
|
|
199
|
+
*
|
|
200
|
+
* @public
|
|
201
|
+
* @static
|
|
202
|
+
* @param {string} input
|
|
203
|
+
* @param {number} [decimal=18]
|
|
204
|
+
* @returns {BN}
|
|
205
|
+
*/
|
|
206
|
+
export declare const fromTokenToUnit: (input: string | number, decimal?: number) => BN;
|
|
2
207
|
/**
|
|
3
208
|
* Validates if a value is an Uint8Array.
|
|
4
209
|
*
|
|
@@ -7,7 +212,24 @@ import * as bnJs from 'bn.js';
|
|
|
7
212
|
* @param {*} value - value to validate
|
|
8
213
|
* @returns {Boolean} boolean indicating if a value is an Uint8Array
|
|
9
214
|
*/
|
|
10
|
-
declare function isUint8Array(value:
|
|
215
|
+
export declare function isUint8Array(value: $TSFixMe): boolean;
|
|
216
|
+
/**
|
|
217
|
+
* Generate a random UUID
|
|
218
|
+
*
|
|
219
|
+
* @public
|
|
220
|
+
* @static
|
|
221
|
+
* @returns {string} Generated uuid
|
|
222
|
+
*/
|
|
223
|
+
export declare function UUID(): string;
|
|
224
|
+
/**
|
|
225
|
+
* Check if a string is valid UUID
|
|
226
|
+
*
|
|
227
|
+
* @public
|
|
228
|
+
* @static
|
|
229
|
+
* @param {string} str
|
|
230
|
+
* @returns {boolean}
|
|
231
|
+
*/
|
|
232
|
+
export declare function isUUID(str: string): boolean;
|
|
11
233
|
/**
|
|
12
234
|
* Convert input to Uint8Array on best effort, base64 node supported
|
|
13
235
|
*
|
|
@@ -17,7 +239,7 @@ declare function isUint8Array(value: any): boolean;
|
|
|
17
239
|
* @returns {Uint8Array}
|
|
18
240
|
* @throws {Error}
|
|
19
241
|
*/
|
|
20
|
-
declare function toUint8Array(v:
|
|
242
|
+
export declare function toUint8Array(v: $TSFixMe): Uint8Array;
|
|
21
243
|
/**
|
|
22
244
|
* Convert input to Buffer on best effort, base64 not supported
|
|
23
245
|
*
|
|
@@ -27,7 +249,7 @@ declare function toUint8Array(v: any): Uint8Array;
|
|
|
27
249
|
* @returns {buffer}
|
|
28
250
|
* @throws {Error}
|
|
29
251
|
*/
|
|
30
|
-
declare function toBuffer(v:
|
|
252
|
+
export declare function toBuffer(v: $TSFixMe): Buffer;
|
|
31
253
|
/**
|
|
32
254
|
* Convert input to base58btc format on best effort
|
|
33
255
|
*
|
|
@@ -37,7 +259,7 @@ declare function toBuffer(v: any): any;
|
|
|
37
259
|
* @returns {string}
|
|
38
260
|
* @throws {Error}
|
|
39
261
|
*/
|
|
40
|
-
declare function toBase58(v:
|
|
262
|
+
export declare function toBase58(v: $TSFixMe): string;
|
|
41
263
|
/**
|
|
42
264
|
* Decode base58 string
|
|
43
265
|
*
|
|
@@ -46,7 +268,7 @@ declare function toBase58(v: any): string;
|
|
|
46
268
|
* @param {string} v
|
|
47
269
|
* @returns {buffer}
|
|
48
270
|
*/
|
|
49
|
-
declare function fromBase58(v: string):
|
|
271
|
+
export declare function fromBase58(v: string): Buffer;
|
|
50
272
|
/**
|
|
51
273
|
* Convert input to base64 format
|
|
52
274
|
*
|
|
@@ -57,7 +279,7 @@ declare function fromBase58(v: string): any;
|
|
|
57
279
|
* @returns {string}
|
|
58
280
|
* @throws {Error}
|
|
59
281
|
*/
|
|
60
|
-
declare function toBase64(v:
|
|
282
|
+
export declare function toBase64(v: $TSFixMe, escape?: boolean): string;
|
|
61
283
|
/**
|
|
62
284
|
* Decode base64(base64_url) string to buffer
|
|
63
285
|
*
|
|
@@ -66,117 +288,73 @@ declare function toBase64(v: any, escape?: typeof escape): string;
|
|
|
66
288
|
* @param {string} v
|
|
67
289
|
* @returns {buffer}
|
|
68
290
|
*/
|
|
69
|
-
declare function fromBase64(v: string):
|
|
70
|
-
/**
|
|
71
|
-
* Generate a random UUID
|
|
72
|
-
*
|
|
73
|
-
* @public
|
|
74
|
-
* @static
|
|
75
|
-
* @returns {string} Generated uuid
|
|
76
|
-
*/
|
|
77
|
-
declare function UUID(): string;
|
|
78
|
-
/**
|
|
79
|
-
* Check if a string is valid UUID
|
|
80
|
-
*
|
|
81
|
-
* @public
|
|
82
|
-
* @static
|
|
83
|
-
* @param {string} str
|
|
84
|
-
* @returns {boolean}
|
|
85
|
-
*/
|
|
86
|
-
declare function isUUID(str: string): boolean;
|
|
291
|
+
export declare function fromBase64(v: string): Buffer;
|
|
87
292
|
/**
|
|
88
|
-
* Convert
|
|
293
|
+
* Convert did to address: remove `did:abt:` prefix
|
|
89
294
|
*
|
|
90
295
|
* @public
|
|
91
296
|
* @static
|
|
92
297
|
* @param {string} did - address string
|
|
93
298
|
* @returns {string}
|
|
94
299
|
*/
|
|
95
|
-
declare function
|
|
300
|
+
export declare function toAddress(did: string): string;
|
|
96
301
|
/**
|
|
97
|
-
* Convert
|
|
302
|
+
* Convert address to did: prepend `did:abt:` prefix
|
|
98
303
|
*
|
|
99
304
|
* @public
|
|
100
305
|
* @static
|
|
101
306
|
* @param {string} did - address string
|
|
102
307
|
* @returns {string}
|
|
103
308
|
*/
|
|
104
|
-
declare function
|
|
105
|
-
declare
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
toDid: typeof toDid;
|
|
135
|
-
toAddress: typeof toAddress;
|
|
136
|
-
formatTxType: (type: any) => any;
|
|
137
|
-
leftPad: any;
|
|
138
|
-
rightPad: any;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* The structure of a forge wallet type
|
|
144
|
-
*
|
|
145
|
-
* @public
|
|
146
|
-
* @static
|
|
147
|
-
* @global
|
|
148
|
-
* @typedef {Object} DidType
|
|
149
|
-
* @prop {number} role - Enum field to identify wallet role type
|
|
150
|
-
* @prop {number} pk - Crypto algorithm to derive publicKey from the secretKey
|
|
151
|
-
* @prop {number} hash - Hash algorithm used to hash data before sign them
|
|
152
|
-
*/
|
|
153
|
-
|
|
309
|
+
export declare function toDid(address: string): string;
|
|
310
|
+
export declare const formatTxType: (type: string) => string;
|
|
311
|
+
import { BytesType } from '@ocap/util';
|
|
312
|
+
import { DidType, DIDType, DIDTypeStr, DIDTypeArg } from '@arcblock/did';
|
|
313
|
+
declare type KeyPairType = {
|
|
314
|
+
sk?: BytesType;
|
|
315
|
+
pk?: BytesType;
|
|
316
|
+
address?: string;
|
|
317
|
+
};
|
|
318
|
+
export declare type SerializedWallet = {
|
|
319
|
+
type: DIDTypeStr;
|
|
320
|
+
pk: string;
|
|
321
|
+
sk: string;
|
|
322
|
+
address: string;
|
|
323
|
+
};
|
|
324
|
+
export declare type WalletObject = {
|
|
325
|
+
type: DIDType;
|
|
326
|
+
secretKey: BytesType;
|
|
327
|
+
publicKey: BytesType;
|
|
328
|
+
address: string;
|
|
329
|
+
hash: (data: BytesType, round?: number) => string;
|
|
330
|
+
sign: (data: BytesType, hashBeforeSign?: boolean) => BytesType;
|
|
331
|
+
verify: (data: BytesType, signature: BytesType, hashBeforeVerify?: boolean) => boolean;
|
|
332
|
+
ethHash: (data: string) => string;
|
|
333
|
+
ethSign: (data: string, hashBeforeSign?: boolean) => string;
|
|
334
|
+
ethVerify: (data: string, signature: BytesType, hashBeforeVerify?: boolean) => boolean;
|
|
335
|
+
toAddress: () => string;
|
|
336
|
+
toJSON: () => SerializedWallet;
|
|
337
|
+
};
|
|
338
|
+
export declare const WalletType: typeof DidType;
|
|
154
339
|
/**
|
|
155
|
-
*
|
|
340
|
+
* Generate an wallet instance that can be used to sign a message or verify a signature
|
|
156
341
|
*
|
|
157
342
|
* @public
|
|
158
343
|
* @static
|
|
159
|
-
* @param {
|
|
160
|
-
* @
|
|
161
|
-
* @
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
* const { types } = require('@ocap/mcrypto');
|
|
165
|
-
*
|
|
166
|
-
* const type = DidType({
|
|
167
|
-
* role: types.RoleType.ROLE_APPLICATION,
|
|
168
|
-
* pk: types.KeyType.ED25519,
|
|
169
|
-
* hash: types.HashType.SHA3,
|
|
170
|
-
* });
|
|
344
|
+
* @param {object} keyPair - the key pair
|
|
345
|
+
* @param {string} keyPair.sk - the secretKey
|
|
346
|
+
* @param {string} keyPair.pk - the wallet publicKey
|
|
347
|
+
* @param {DIDTypeArg} [type='default'] - wallet type
|
|
348
|
+
* @returns {WalletObject} wallet object that can be used to sign/verify/getAddress
|
|
171
349
|
*/
|
|
172
|
-
declare function
|
|
350
|
+
export declare function Wallet(keyPair: KeyPairType, t?: DIDTypeArg): WalletObject;
|
|
173
351
|
/**
|
|
174
352
|
* Generate a wallet from secretKey
|
|
175
353
|
*
|
|
176
354
|
* @public
|
|
177
355
|
* @static
|
|
178
356
|
* @param {string} sk - the secret key, `hex encoded string`
|
|
179
|
-
* @param {
|
|
357
|
+
* @param {DIDTypeArg} [type='default'] - wallet type
|
|
180
358
|
* @returns {WalletObject} wallet object that can be used to sign/verify/getAddress
|
|
181
359
|
* @example
|
|
182
360
|
* const assert = require('assert');
|
|
@@ -193,30 +371,17 @@ declare function DidType(type?: DidType | string): object;
|
|
|
193
371
|
* assert.equal(signature, sig, "signature should match");
|
|
194
372
|
* assert.ok(wallet.verify(message, signature), "signature should be verified");
|
|
195
373
|
*/
|
|
196
|
-
declare function fromSecretKey(sk:
|
|
374
|
+
export declare function fromSecretKey(sk: BytesType, _type?: DIDTypeArg): WalletObject;
|
|
197
375
|
/**
|
|
198
376
|
* Generate a wallet from publicKey
|
|
199
377
|
*
|
|
200
378
|
* @public
|
|
201
379
|
* @static
|
|
202
380
|
* @param {string} pk - the public key, `hex encoded string`
|
|
203
|
-
* @param {
|
|
204
|
-
* @returns {WalletObject} wallet object that can be used to sign/verify/getAddress
|
|
205
|
-
*/
|
|
206
|
-
declare function fromPublicKey(pk: string, _type?: string): WalletObject;
|
|
207
|
-
/**
|
|
208
|
-
* Generate a wallet by generating a random secretKey
|
|
209
|
-
*
|
|
210
|
-
* @public
|
|
211
|
-
* @static
|
|
212
|
-
* @param {DidType} [type='default'] - wallet type
|
|
381
|
+
* @param {DIDTypeArg} [type='default'] - wallet type
|
|
213
382
|
* @returns {WalletObject} wallet object that can be used to sign/verify/getAddress
|
|
214
|
-
* @example
|
|
215
|
-
* const { fromRandom } = require('@ocap/wallet');
|
|
216
|
-
* const wallet = fromRandom();
|
|
217
|
-
* // Do something with wallet
|
|
218
383
|
*/
|
|
219
|
-
declare function
|
|
384
|
+
export declare function fromPublicKey(pk: BytesType, _type?: DIDTypeArg): WalletObject;
|
|
220
385
|
/**
|
|
221
386
|
* Generate a wallet from address (did)
|
|
222
387
|
*
|
|
@@ -226,29 +391,21 @@ declare function fromRandom(_type?: string): WalletObject;
|
|
|
226
391
|
* @static
|
|
227
392
|
* @param {string} address - the wallet address
|
|
228
393
|
* @returns {WalletObject} wallet object that can be used to sign/verify/getAddress
|
|
229
|
-
* @example
|
|
230
|
-
* const assert = require('assert');
|
|
231
|
-
* const { fromAddress } = require('@ocap/wallet');
|
|
232
|
-
*
|
|
233
|
-
* const address = 'zNKtCNqYWLYWYW3gWRA1vnRykfCBZYHZvzKr';
|
|
234
|
-
* const wallet = fromAddress(address);
|
|
235
|
-
* console.log(wallet.toJSON());
|
|
236
394
|
*/
|
|
237
|
-
declare function fromAddress(address: string): WalletObject;
|
|
395
|
+
export declare function fromAddress(address: string): WalletObject;
|
|
238
396
|
/**
|
|
239
|
-
*
|
|
397
|
+
* Generate a wallet by generating a random secretKey
|
|
240
398
|
*
|
|
241
399
|
* @public
|
|
242
400
|
* @static
|
|
243
|
-
* @param {
|
|
401
|
+
* @param {DIDTypeArg} [type='default'] - wallet type
|
|
244
402
|
* @returns {WalletObject} wallet object that can be used to sign/verify/getAddress
|
|
245
|
-
* @example
|
|
246
|
-
* const { fromJSON, fromRandom } = require('@ocap/wallet');
|
|
247
|
-
* const wallet = fromRandom();
|
|
248
|
-
* const wallet2 = fromJSON(wallet.toJSON());
|
|
249
|
-
* // wallet2 is identical to wallet
|
|
250
403
|
*/
|
|
251
|
-
declare function
|
|
404
|
+
export declare function fromRandom(_type?: DIDTypeArg): WalletObject;
|
|
405
|
+
/**
|
|
406
|
+
* Generating a wallet from a serialized json presentation of another wallet
|
|
407
|
+
*/
|
|
408
|
+
export declare function fromJSON(json: SerializedWallet): WalletObject;
|
|
252
409
|
/**
|
|
253
410
|
* Check if an object is valid wallet object
|
|
254
411
|
*
|
|
@@ -257,61 +414,8 @@ declare function fromJSON(json: any): WalletObject;
|
|
|
257
414
|
* @param {object} wallet
|
|
258
415
|
* @param {boolean} canSign - should the wallet support sign
|
|
259
416
|
*/
|
|
260
|
-
declare function isValid(wallet:
|
|
261
|
-
|
|
262
|
-
* @public
|
|
263
|
-
* @static
|
|
264
|
-
* @global
|
|
265
|
-
* @name WalletObject
|
|
266
|
-
* @typedef WalletObject
|
|
267
|
-
* @prop {DidType} type - Indicates the wallet type
|
|
268
|
-
* @prop {secretKey} secretKey - Wallet secretKey
|
|
269
|
-
* @prop {publicKey} publicKey - Wallet publicKey
|
|
270
|
-
* @prop {function} sign - Sign `data`, data is hashed using the `HashType` defined in type before signing
|
|
271
|
-
* @prop {function} verify - Verify `signature`, data is hashed using the `HashType` defined in type before verifying
|
|
272
|
-
* @prop {function} toAddress - Get wallet address without `did:abt:` prefix
|
|
273
|
-
* @prop {function} toJSON - Serialize wallet to json object, checkout {@link fromJSON} for deserialisation
|
|
274
|
-
*/
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* Generate an wallet instance that can be used to sign a message or verify a signature
|
|
278
|
-
*
|
|
279
|
-
* @public
|
|
280
|
-
* @static
|
|
281
|
-
* @param {object} keyPair - the key pair
|
|
282
|
-
* @param {string} keyPair.sk - the secretKey
|
|
283
|
-
* @param {string} keyPair.pk - the wallet publicKey
|
|
284
|
-
* @param {DidType} [type='default'] - wallet type
|
|
285
|
-
* @returns {WalletObject} wallet object that can be used to sign/verify/getAddress
|
|
286
|
-
*/
|
|
287
|
-
declare function Wallet(keyPair: ForgeSdkWallet.T100, type?: typeof DidType): WalletObject;
|
|
288
|
-
declare namespace ForgeSdkWallet {
|
|
289
|
-
export interface WalletObject {
|
|
290
|
-
type: typeof DidType;
|
|
291
|
-
secretKey: any;
|
|
292
|
-
publicKey: any;
|
|
293
|
-
sign: (...args: any[]) => any;
|
|
294
|
-
verify: (...args: any[]) => any;
|
|
295
|
-
toAddress: (...args: any[]) => any;
|
|
296
|
-
toJSON: (...args: any[]) => any;
|
|
297
|
-
}
|
|
298
|
-
export interface T100 {
|
|
299
|
-
sk: string;
|
|
300
|
-
pk: string;
|
|
301
|
-
}
|
|
302
|
-
export interface T101 {
|
|
303
|
-
fromSecretKey: typeof fromSecretKey;
|
|
304
|
-
fromPublicKey: typeof fromPublicKey;
|
|
305
|
-
fromRandom: typeof fromRandom;
|
|
306
|
-
fromAddress: typeof fromAddress;
|
|
307
|
-
fromDID: typeof fromAddress;
|
|
308
|
-
fromJSON: typeof fromJSON;
|
|
309
|
-
isValid: typeof isValid;
|
|
310
|
-
Wallet: typeof Wallet;
|
|
311
|
-
WalletType: typeof DidType;
|
|
312
|
-
DidType: typeof DidType;
|
|
313
|
-
}
|
|
314
|
-
}
|
|
417
|
+
export declare function isValid(wallet: WalletObject, canSign?: boolean): boolean;
|
|
418
|
+
export {};
|
|
315
419
|
|
|
316
420
|
import * as LibMessage from './lib/message';
|
|
317
421
|
declare const _OcapMessage: typeof LibMessage;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ocap/sdk",
|
|
3
3
|
"description": "Forge javascript SDK packages all-in-one",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.17.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "wangshijun",
|
|
7
7
|
"email": "shijun@arcblock.io",
|
|
@@ -18,11 +18,11 @@
|
|
|
18
18
|
"access": "public"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@arcblock/did-util": "1.
|
|
22
|
-
"@ocap/client": "1.
|
|
23
|
-
"@ocap/message": "1.
|
|
24
|
-
"@ocap/util": "1.
|
|
25
|
-
"@ocap/wallet": "1.
|
|
21
|
+
"@arcblock/did-util": "1.17.0",
|
|
22
|
+
"@ocap/client": "1.17.0",
|
|
23
|
+
"@ocap/message": "1.17.0",
|
|
24
|
+
"@ocap/util": "1.17.0",
|
|
25
|
+
"@ocap/wallet": "1.17.0",
|
|
26
26
|
"debug": "^4.3.3",
|
|
27
27
|
"react-app-polyfill": "^1.0.1"
|
|
28
28
|
},
|
|
@@ -79,5 +79,5 @@
|
|
|
79
79
|
"test": "jest --forceExit --detectOpenHandles",
|
|
80
80
|
"coverage": "yarn test -- --coverage"
|
|
81
81
|
},
|
|
82
|
-
"gitHead": "
|
|
82
|
+
"gitHead": "f0944b60a5fb4115e1a3727bb07f68174bc56c5c"
|
|
83
83
|
}
|