@ocap/sdk 1.17.1 → 1.17.4

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.
Files changed (2) hide show
  1. package/index.d.ts +43 -131
  2. package/package.json +7 -7
package/index.d.ts CHANGED
@@ -1,9 +1,14 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="jest" />
3
+ import { LiteralUnion } from 'type-fest';
2
4
  import rightPad from 'lodash/padEnd';
3
5
  import leftPad from 'lodash/padStart';
4
6
  import BN from 'bn.js';
5
7
  export declare type BytesType = string | Buffer | Uint8Array;
6
- export declare type EncodingType = 'hex' | 'base16' | 'base58' | 'base64' | 'Uint8Array' | 'buffer';
8
+ export declare type EncodingType = LiteralUnion<
9
+ 'hex' | 'base16' | 'base58' | 'base64' | 'Uint8Array' | 'buffer',
10
+ string
11
+ >;
7
12
  export declare type KeyPairType = {
8
13
  publicKey: BytesType;
9
14
  secretKey: BytesType;
@@ -11,8 +16,8 @@ export declare type KeyPairType = {
11
16
  export { BN, leftPad, rightPad };
12
17
  /**
13
18
  * 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
19
+ * @param {string|number|BN} `arg` input a string number, hex string number, number, BigNumber or BN object
20
+ * @return {BN} `output` BN object of the number
16
21
  * @throws if the argument is not an array, object that isn't a bignumber, not a string number or number
17
22
  */
18
23
  export declare const numberToBN: (arg: string | number | BN) => BN;
@@ -31,10 +36,8 @@ export declare const isHexPrefixed: (str: string) => boolean;
31
36
  *
32
37
  * @public
33
38
  * @static
34
- * @param {String} str the string value
35
- * @return {String|Optional} a string by pass if necessary
36
39
  */
37
- export declare const stripHexPrefix: (str: $TSFixMe) => any;
40
+ export declare const stripHexPrefix: (str: string | any) => any;
38
41
  /**
39
42
  * Returns true if object is BN, otherwise false
40
43
  *
@@ -114,7 +117,7 @@ export declare const hexToUtf8: (hex: string) => string;
114
117
  * @param {String|Number|BN} value
115
118
  * @returns {Number}
116
119
  */
117
- export declare const hexToNumber: (value: string | number | BN) => string | number | BN;
120
+ export declare const hexToNumber: (value: string | number | BN) => number;
118
121
  /**
119
122
  * Converts value to hex representation
120
123
  *
@@ -146,7 +149,7 @@ export declare const bytesToHex: (bytes: $TSFixMe) => string;
146
149
  * @param {String} hex
147
150
  * @returns {Array} the byte array
148
151
  */
149
- export declare const hexToBytes: (hex: $TSFixMe) => number[];
152
+ export declare const hexToBytes: (hex: $TSFixMe) => Array<any>;
150
153
  /**
151
154
  * Auto converts any given value into it's hex representation.
152
155
  * And even stringify objects before.
@@ -180,14 +183,6 @@ export declare const toHex: (
180
183
  export declare const numberToString: (arg: $TSFixMe) => any;
181
184
  /**
182
185
  * 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
186
  */
192
187
  export declare const fromUnitToToken: (
193
188
  input: string | number | BN,
@@ -196,119 +191,55 @@ export declare const fromUnitToToken: (
196
191
  ) => string;
197
192
  /**
198
193
  * 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
194
  */
206
195
  export declare const fromTokenToUnit: (input: string | number, decimal?: number) => BN;
207
196
  /**
208
197
  * Validates if a value is an Uint8Array.
209
- *
210
- * @public
211
- * @static
212
- * @param {*} value - value to validate
213
- * @returns {Boolean} boolean indicating if a value is an Uint8Array
214
198
  */
215
199
  export declare function isUint8Array(value: $TSFixMe): boolean;
216
200
  /**
217
201
  * Generate a random UUID
218
- *
219
- * @public
220
- * @static
221
- * @returns {string} Generated uuid
222
202
  */
223
203
  export declare function UUID(): string;
224
204
  /**
225
205
  * Check if a string is valid UUID
226
- *
227
- * @public
228
- * @static
229
- * @param {string} str
230
- * @returns {boolean}
231
206
  */
232
207
  export declare function isUUID(str: string): boolean;
233
208
  /**
234
209
  * Convert input to Uint8Array on best effort, base64 node supported
235
- *
236
- * @public
237
- * @static
238
- * @param {buffer|base58|hex|Uint8Array|string} v
239
- * @returns {Uint8Array}
240
- * @throws {Error}
241
210
  */
242
- export declare function toUint8Array(v: $TSFixMe): Uint8Array;
211
+ export declare function toUint8Array(v: any): Uint8Array;
243
212
  /**
244
213
  * Convert input to Buffer on best effort, base64 not supported
245
- *
246
- * @public
247
- * @static
248
- * @param {buffer|base58|hex|Uint8Array} v
249
- * @returns {buffer}
250
- * @throws {Error}
251
214
  */
252
- export declare function toBuffer(v: $TSFixMe): Buffer;
215
+ export declare function toBuffer(v: any): Buffer;
253
216
  /**
254
217
  * Convert input to base58btc format on best effort
255
- *
256
- * @public
257
- * @static
258
- * @param {buffer|base58|hex|Uint8Array} v
259
- * @returns {string}
260
- * @throws {Error}
261
218
  */
262
- export declare function toBase58(v: $TSFixMe): string;
219
+ export declare function toBase58(v: any): string;
263
220
  /**
264
221
  * Decode base58 string
265
- *
266
- * @public
267
- * @static
268
- * @param {string} v
269
- * @returns {buffer}
270
222
  */
271
223
  export declare function fromBase58(v: string): Buffer;
272
224
  /**
273
225
  * Convert input to base64 format
274
- *
275
- * @public
276
- * @static
277
- * @param {buffer|base58|hex|Uint8Array} v
278
- * @param {escape} [escape=true]
279
- * @returns {string}
280
- * @throws {Error}
281
226
  */
282
- export declare function toBase64(v: $TSFixMe, escape?: boolean): string;
227
+ export declare function toBase64(v: any, escape?: boolean): string;
283
228
  /**
284
229
  * Decode base64(base64_url) string to buffer
285
- *
286
- * @public
287
- * @static
288
- * @param {string} v
289
- * @returns {buffer}
290
230
  */
291
231
  export declare function fromBase64(v: string): Buffer;
292
232
  /**
293
233
  * Convert did to address: remove `did:abt:` prefix
294
- *
295
- * @public
296
- * @static
297
- * @param {string} did - address string
298
- * @returns {string}
299
234
  */
300
235
  export declare function toAddress(did: string): string;
301
236
  /**
302
237
  * Convert address to did: prepend `did:abt:` prefix
303
- *
304
- * @public
305
- * @static
306
- * @param {string} did - address string
307
- * @returns {string}
308
238
  */
309
239
  export declare function toDid(address: string): string;
310
- export declare const formatTxType: (type: string) => string;
311
- import { BytesType } from '@ocap/util';
240
+ export declare function formatTxType(type: string): any;
241
+ /// <reference types="node" />
242
+ import { EncodingType, BytesType } from '@ocap/util';
312
243
  import { DidType, DIDType, DIDTypeStr, DIDTypeArg } from '@arcblock/did';
313
244
  declare type KeyPairType = {
314
245
  sk?: BytesType;
@@ -321,41 +252,43 @@ export declare type SerializedWallet = {
321
252
  sk: string;
322
253
  address: string;
323
254
  };
324
- export declare type WalletObject = {
255
+ export interface WalletObject {
325
256
  type: DIDType;
326
257
  secretKey: BytesType;
327
258
  publicKey: BytesType;
328
259
  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
- };
260
+ hash(data: BytesType, round?: number, encoding?: 'hex'): string;
261
+ hash(data: BytesType, round?: number, encoding?: 'base16'): string;
262
+ hash(data: BytesType, round?: number, encoding?: 'base58'): string;
263
+ hash(data: BytesType, round?: number, encoding?: 'base64'): string;
264
+ hash(data: BytesType, round?: number, encoding?: 'buffer'): Buffer;
265
+ hash(data: BytesType, round?: number, encoding?: 'Uint8Array'): Uint8Array;
266
+ hash(data: BytesType, round?: number, encoding?: EncodingType): BytesType;
267
+ sign(data: BytesType, hashBeforeSign?: boolean, encoding?: 'hex'): string;
268
+ sign(data: BytesType, hashBeforeSign?: boolean, encoding?: 'base16'): string;
269
+ sign(data: BytesType, hashBeforeSign?: boolean, encoding?: 'base58'): string;
270
+ sign(data: BytesType, hashBeforeSign?: boolean, encoding?: 'base64'): string;
271
+ sign(data: BytesType, hashBeforeSign?: boolean, encoding?: 'buffer'): Buffer;
272
+ sign(data: BytesType, hashBeforeSign?: boolean, encoding?: 'Uint8Array'): Uint8Array;
273
+ sign(data: BytesType, hashBeforeSign?: boolean, encoding?: EncodingType): BytesType;
274
+ verify(data: BytesType, signature: BytesType, hashBeforeVerify?: boolean): boolean;
275
+ ethHash(data: string): string;
276
+ ethSign(data: string, hashBeforeSign?: boolean): string;
277
+ ethVerify(data: string, signature: string, hashBeforeVerify?: boolean): boolean;
278
+ toJSON(): SerializedWallet;
279
+ /**
280
+ * @deprecated ES6: use `wallet.address` instead
281
+ */
282
+ toAddress(): string;
283
+ }
338
284
  export declare const WalletType: typeof DidType;
339
285
  /**
340
286
  * Generate an wallet instance that can be used to sign a message or verify a signature
341
- *
342
- * @public
343
- * @static
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
349
287
  */
350
288
  export declare function Wallet(keyPair: KeyPairType, t?: DIDTypeArg): WalletObject;
351
289
  /**
352
290
  * Generate a wallet from secretKey
353
291
  *
354
- * @public
355
- * @static
356
- * @param {string} sk - the secret key, `hex encoded string`
357
- * @param {DIDTypeArg} [type='default'] - wallet type
358
- * @returns {WalletObject} wallet object that can be used to sign/verify/getAddress
359
292
  * @example
360
293
  * const assert = require('assert');
361
294
  * const { fromSecretKey } = require('@ocap/wallet');
@@ -374,32 +307,16 @@ export declare function Wallet(keyPair: KeyPairType, t?: DIDTypeArg): WalletObje
374
307
  export declare function fromSecretKey(sk: BytesType, _type?: DIDTypeArg): WalletObject;
375
308
  /**
376
309
  * Generate a wallet from publicKey
377
- *
378
- * @public
379
- * @static
380
- * @param {string} pk - the public key, `hex encoded string`
381
- * @param {DIDTypeArg} [type='default'] - wallet type
382
- * @returns {WalletObject} wallet object that can be used to sign/verify/getAddress
383
310
  */
384
311
  export declare function fromPublicKey(pk: BytesType, _type?: DIDTypeArg): WalletObject;
385
312
  /**
386
313
  * Generate a wallet from address (did)
387
314
  *
388
315
  * Since we do not know the publicKey and secretKey, this kind of wallet cannot be used for signing and verifying
389
- *
390
- * @public
391
- * @static
392
- * @param {string} address - the wallet address
393
- * @returns {WalletObject} wallet object that can be used to sign/verify/getAddress
394
316
  */
395
317
  export declare function fromAddress(address: string): WalletObject;
396
318
  /**
397
319
  * Generate a wallet by generating a random secretKey
398
- *
399
- * @public
400
- * @static
401
- * @param {DIDTypeArg} [type='default'] - wallet type
402
- * @returns {WalletObject} wallet object that can be used to sign/verify/getAddress
403
320
  */
404
321
  export declare function fromRandom(_type?: DIDTypeArg): WalletObject;
405
322
  /**
@@ -408,11 +325,6 @@ export declare function fromRandom(_type?: DIDTypeArg): WalletObject;
408
325
  export declare function fromJSON(json: SerializedWallet): WalletObject;
409
326
  /**
410
327
  * Check if an object is valid wallet object
411
- *
412
- * @public
413
- * @static
414
- * @param {object} wallet
415
- * @param {boolean} canSign - should the wallet support sign
416
328
  */
417
329
  export declare function isValid(wallet: WalletObject, canSign?: boolean): boolean;
418
330
  export {};
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.17.1",
4
+ "version": "1.17.4",
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.17.1",
22
- "@ocap/client": "1.17.1",
23
- "@ocap/message": "1.17.1",
24
- "@ocap/util": "1.17.1",
25
- "@ocap/wallet": "1.17.1",
21
+ "@arcblock/did-util": "1.17.4",
22
+ "@ocap/client": "1.17.4",
23
+ "@ocap/message": "1.17.4",
24
+ "@ocap/util": "1.17.4",
25
+ "@ocap/wallet": "1.17.4",
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": "ca2ac264d9d6358680d5be99fcdd4685d0c999fc"
82
+ "gitHead": "296f3dccba7a691244212a51481fffcf142fc138"
83
83
  }