postchain-client 1.0.0 → 1.0.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.
@@ -102,6 +102,8 @@
102
102
 
103
103
  /*! ./hash/utils */
104
104
 
105
+ /*! ./index */
106
+
105
107
  /*! ./inherits_browser.js */
106
108
 
107
109
  /*! ./key */
@@ -134,6 +136,8 @@
134
136
 
135
137
  /*! ./restclientutil */
136
138
 
139
+ /*! ./serialization */
140
+
137
141
  /*! ./sha/1 */
138
142
 
139
143
  /*! ./sha/224 */
@@ -300,6 +304,10 @@
300
304
  !*** ./src/gtv/index.ts ***!
301
305
  \**************************/
302
306
 
307
+ /*!**************************!*\
308
+ !*** ./src/gtx/index.ts ***!
309
+ \**************************/
310
+
303
311
  /*!***************************!*\
304
312
  !*** ./src/gtx/errors.ts ***!
305
313
  \***************************/
@@ -344,6 +352,10 @@
344
352
  !*** ./src/restclient/errors.ts ***!
345
353
  \**********************************/
346
354
 
355
+ /*!************************************!*\
356
+ !*** ./node_modules/tr46/index.js ***!
357
+ \************************************/
358
+
347
359
  /*!************************************!*\
348
360
  !*** ./src/merkle/merkleHelper.ts ***!
349
361
  \************************************/
@@ -364,10 +376,6 @@
364
376
  !*** ./node_modules/brorand/index.js ***!
365
377
  \***************************************/
366
378
 
367
- /*!****************************************!*\
368
- !*** ../../node_modules/tr46/index.js ***!
369
- \****************************************/
370
-
371
379
  /*!*****************************************!*\
372
380
  !*** ./node_modules/secp256k1/index.js ***!
373
381
  \*****************************************/
@@ -408,6 +416,10 @@
408
416
  !*** ./node_modules/secp256k1/elliptic.js ***!
409
417
  \********************************************/
410
418
 
419
+ /*!********************************************!*\
420
+ !*** ./node_modules/whatwg-url/lib/URL.js ***!
421
+ \********************************************/
422
+
411
423
  /*!********************************************!*\
412
424
  !*** ./src/merkle/merklehashcalculator.js ***!
413
425
  \********************************************/
@@ -432,6 +444,10 @@
432
444
  !*** ./node_modules/node-gyp-build/index.js ***!
433
445
  \**********************************************/
434
446
 
447
+ /*!**********************************************!*\
448
+ !*** ./node_modules/whatwg-url/lib/utils.js ***!
449
+ \**********************************************/
450
+
435
451
  /*!**********************************************!*\
436
452
  !*** ./src/chromia/chromiaClientProvider.ts ***!
437
453
  \**********************************************/
@@ -445,12 +461,12 @@
445
461
  \***********************************************/
446
462
 
447
463
  /*!***********************************************!*\
448
- !*** ./src/merkle/proof/merklehashcarrier.js ***!
464
+ !*** ./node_modules/node-fetch/lib/index.mjs ***!
449
465
  \***********************************************/
450
466
 
451
- /*!************************************************!*\
452
- !*** ../../node_modules/whatwg-url/lib/URL.js ***!
453
- \************************************************/
467
+ /*!***********************************************!*\
468
+ !*** ./src/merkle/proof/merklehashcarrier.js ***!
469
+ \***********************************************/
454
470
 
455
471
  /*!************************************************!*\
456
472
  !*** ./node_modules/hash.js/lib/hash/sha/1.js ***!
@@ -476,9 +492,13 @@
476
492
  !*** ./node_modules/hmac-drbg/lib/hmac-drbg.js ***!
477
493
  \*************************************************/
478
494
 
479
- /*!**************************************************!*\
480
- !*** ../../node_modules/whatwg-url/lib/utils.js ***!
481
- \**************************************************/
495
+ /*!*************************************************!*\
496
+ !*** ./node_modules/tr46/lib/mappingTable.json ***!
497
+ \*************************************************/
498
+
499
+ /*!*************************************************!*\
500
+ !*** ./node_modules/whatwg-url/lib/URL-impl.js ***!
501
+ \*************************************************/
482
502
 
483
503
  /*!**************************************************!*\
484
504
  !*** ./node_modules/hash.js/lib/hash/sha/224.js ***!
@@ -497,15 +517,15 @@
497
517
  \**************************************************/
498
518
 
499
519
  /*!***************************************************!*\
500
- !*** ../../node_modules/node-fetch/lib/index.mjs ***!
520
+ !*** ./node_modules/inherits/inherits_browser.js ***!
501
521
  \***************************************************/
502
522
 
503
523
  /*!***************************************************!*\
504
- !*** ./node_modules/inherits/inherits_browser.js ***!
524
+ !*** ./node_modules/minimalistic-assert/index.js ***!
505
525
  \***************************************************/
506
526
 
507
527
  /*!***************************************************!*\
508
- !*** ./node_modules/minimalistic-assert/index.js ***!
528
+ !*** ./node_modules/whatwg-url/lib/public-api.js ***!
509
529
  \***************************************************/
510
530
 
511
531
  /*!****************************************************!*\
@@ -516,14 +536,6 @@
516
536
  !*** ./src/merkle/proof/merkleprooftreefactory.js ***!
517
537
  \****************************************************/
518
538
 
519
- /*!*****************************************************!*\
520
- !*** ../../node_modules/tr46/lib/mappingTable.json ***!
521
- \*****************************************************/
522
-
523
- /*!*****************************************************!*\
524
- !*** ../../node_modules/whatwg-url/lib/URL-impl.js ***!
525
- \*****************************************************/
526
-
527
539
  /*!*****************************************************!*\
528
540
  !*** ./node_modules/asn1.js/lib/asn1/base/index.js ***!
529
541
  \*****************************************************/
@@ -549,12 +561,12 @@
549
561
  \******************************************************/
550
562
 
551
563
  /*!******************************************************!*\
552
- !*** ./src/merkle/proof/merklehashsummaryfactory.js ***!
564
+ !*** ./node_modules/webidl-conversions/lib/index.js ***!
553
565
  \******************************************************/
554
566
 
555
- /*!*******************************************************!*\
556
- !*** ../../node_modules/whatwg-url/lib/public-api.js ***!
557
- \*******************************************************/
567
+ /*!******************************************************!*\
568
+ !*** ./src/merkle/proof/merklehashsummaryfactory.js ***!
569
+ \******************************************************/
558
570
 
559
571
  /*!*******************************************************!*\
560
572
  !*** ./node_modules/asn1.js/lib/asn1/decoders/der.js ***!
@@ -596,10 +608,6 @@
596
608
  !*** ./node_modules/elliptic/lib/elliptic/eddsa/key.js ***!
597
609
  \*********************************************************/
598
610
 
599
- /*!**********************************************************!*\
600
- !*** ../../node_modules/webidl-conversions/lib/index.js ***!
601
- \**********************************************************/
602
-
603
611
  /*!**********************************************************!*\
604
612
  !*** ./node_modules/asn1.js/lib/asn1/constants/index.js ***!
605
613
  \**********************************************************/
@@ -612,6 +620,10 @@
612
620
  !*** ./node_modules/elliptic/lib/elliptic/curve/mont.js ***!
613
621
  \**********************************************************/
614
622
 
623
+ /*!**********************************************************!*\
624
+ !*** ./node_modules/whatwg-url/lib/url-state-machine.js ***!
625
+ \**********************************************************/
626
+
615
627
  /*!***********************************************************!*\
616
628
  !*** ./node_modules/elliptic/lib/elliptic/curve/index.js ***!
617
629
  \***********************************************************/
@@ -636,10 +648,6 @@
636
648
  !*** ./node_modules/minimalistic-crypto-utils/lib/utils.js ***!
637
649
  \*************************************************************/
638
650
 
639
- /*!**************************************************************!*\
640
- !*** ../../node_modules/whatwg-url/lib/url-state-machine.js ***!
641
- \**************************************************************/
642
-
643
651
  /*!***************************************************************!*\
644
652
  !*** ./node_modules/elliptic/lib/elliptic/eddsa/signature.js ***!
645
653
  \***************************************************************/
@@ -1,3 +1,8 @@
1
- import { RestClient } from "../restclient/interfaces";
2
- import { ChromiaClientProvider } from "./interfaces";
3
- export declare function chromiaClientProvider(brid: string, rest: RestClient): ChromiaClientProvider;
1
+ import type { RestClient } from "../restclient/interfaces";
2
+ import type { ChromiaClient } from "./interfaces";
3
+ /**
4
+ * Provides postchain clients that can be used to communicate with dapps within the chromia network
5
+ * @param chain0BRID brid of chain0
6
+ * @param rest rest client configured to node running chain0
7
+ */
8
+ export declare function chromiaClientProvider(chain0BRID: string, rest: RestClient): ChromiaClient;
@@ -1,4 +1,4 @@
1
1
  import { RestClient } from "../restclient/interfaces";
2
- export interface ChromiaClientProvider {
2
+ export interface ChromiaClient {
3
3
  blockchainConnection: (blockchainRid: string) => Promise<RestClient>;
4
4
  }
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- export declare type KeyPair = {
2
+ export type KeyPair = {
3
3
  pubKey: Buffer;
4
4
  privKey: Buffer;
5
5
  };
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ import { GTX, RawGtx } from "./gtx/types";
2
3
  export declare function pgBytes(buffer: Buffer): string;
3
4
  /**
4
5
  * Converts hex string to Buffer
@@ -16,4 +17,7 @@ export declare class PgBytesInputException extends Error {
16
17
  constructor(buffer: Buffer);
17
18
  }
18
19
  export declare function ensureBuffer(value: string | Buffer): Buffer;
20
+ export declare function checkGtvType(value: any): boolean;
21
+ export declare function rawGtxToGtx(rawGtx: RawGtx): GTX;
22
+ export declare function checkGtxType(value: any): boolean;
19
23
  export declare function removeDuplicateSigners(signers: Buffer[]): Buffer[];
@@ -1,6 +1,5 @@
1
1
  import * as serialization from "../gtx/serialization";
2
- import { RawGtxBody } from "../gtx/types";
3
- declare const gtvHash: (obj: RawGtxBody) => Buffer;
4
- declare const encodeGtv: typeof serialization.encodeValue;
5
- declare const decodeGtv: typeof serialization.decodeValue;
6
- export { encodeGtv, decodeGtv, gtvHash };
2
+ declare const gtvHash: (obj: any) => Buffer;
3
+ declare const encode: typeof serialization.encodeValue;
4
+ declare const decode: typeof serialization.decodeValue;
5
+ export { encode, decode, gtvHash };
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
- export declare type RawGtv = null | Buffer | string | number | DictPair | Array<RawGtv> | bigint;
3
- export declare type DictPair = {
2
+ export type RawGtv = null | Buffer | string | number | DictPair | Array<RawGtv> | bigint;
3
+ export type DictPair = {
4
4
  name: string;
5
5
  value: RawGtv;
6
6
  };
@@ -0,0 +1,4 @@
1
+ import * as serialization from "./serialization";
2
+ declare const encode: typeof serialization.encodeValueGtx;
3
+ declare const decode: typeof serialization.decodeValueGtx;
4
+ export { encode, decode };
@@ -1,6 +1,8 @@
1
1
  /// <reference types="node" />
2
2
  import { RawGtx } from "./types";
3
3
  import { RawGtv } from "../gtv/types";
4
- export declare function encodeValue(rawGtx: RawGtx): Buffer;
5
- export declare function decodeValue(bytes: Buffer): RawGtx;
4
+ export declare function encodeValue(rawGtv: RawGtv): Buffer;
5
+ export declare function encodeValueGtx(rawGtx: RawGtx): Buffer;
6
+ export declare function decodeValue(bytes: Buffer): RawGtv;
7
+ export declare function decodeValueGtx(bytes: Buffer): RawGtx;
6
8
  export declare function createTypedArg(value: RawGtv): any;
@@ -1,28 +1,28 @@
1
1
  /// <reference types="node" />
2
2
  import { RawGtv } from "../gtv/types";
3
- export declare type RawGtxOp = [opName: string, args: RawGtv[]];
4
- export declare type RawGtxBody = [
3
+ export type RawGtxOp = [opName: string, args: RawGtv[]];
4
+ export type RawGtxBody = [
5
5
  blockchainRID: Buffer,
6
6
  operations: RawGtxOp[],
7
7
  signers: Buffer[]
8
8
  ];
9
- export declare type RawGtx = [transaction: RawGtxBody, signatures: Buffer[]];
10
- export declare type GTX = {
9
+ export type RawGtx = [transaction: RawGtxBody, signatures: Buffer[]];
10
+ export type GTX = {
11
11
  [x: string]: any;
12
12
  blockchainRID: Buffer;
13
13
  operations: RellOperation[];
14
14
  signers: Buffer[];
15
15
  signatures?: Buffer[];
16
16
  };
17
- export declare type RellOperation = {
17
+ export type RellOperation = {
18
18
  opName: string;
19
19
  args: RawGtv[];
20
20
  };
21
- export declare type SignerPair = {
21
+ export type SignerPair = {
22
22
  pubKey: string;
23
23
  signature: string;
24
24
  };
25
- export declare type BufferSignerPair = {
25
+ export type BufferSignerPair = {
26
26
  pubKey: Buffer;
27
27
  signature: Buffer;
28
28
  };
@@ -1,11 +1,11 @@
1
1
  /// <reference types="node" />
2
- export declare type Step = {
2
+ export type Step = {
3
3
  side: number;
4
4
  hash: Buffer;
5
5
  };
6
- export declare type StringStep = {
6
+ export type StringStep = {
7
7
  side: number;
8
8
  hash: string;
9
9
  };
10
- export declare type Path = Step[];
11
- export declare type StringPath = StringStep[];
10
+ export type Path = Step[];
11
+ export type StringPath = StringStep[];
@@ -2,7 +2,7 @@
2
2
  import { RawGtv } from "../gtv/types";
3
3
  import { BufferSignerPair, SignerPair } from "../gtx/types";
4
4
  import { Path, StringPath } from "../merkle/types";
5
- export declare type RestClientConfig = {
5
+ export type RestClientConfig = {
6
6
  endpointPool: readonly string[];
7
7
  pool: {
8
8
  maxSockets: number;
@@ -11,7 +11,7 @@ export declare type RestClientConfig = {
11
11
  attemptsPerEndpoint: number;
12
12
  attemptInterval: number;
13
13
  };
14
- export declare type RequestOptions = {
14
+ export type RequestOptions = {
15
15
  method: string;
16
16
  url: string;
17
17
  json: boolean;
@@ -20,17 +20,17 @@ export declare type RequestOptions = {
20
20
  maxSockets: number;
21
21
  };
22
22
  };
23
- export declare type QueryObject = {
23
+ export type QueryObject = {
24
24
  type: string;
25
25
  [arg: string]: RawGtv;
26
26
  };
27
- export declare type ServerReturnProof = {
27
+ export type ServerReturnProof = {
28
28
  hash: string;
29
29
  blockHeader: string;
30
30
  signatures: SignerPair[];
31
31
  merklePath: StringPath;
32
32
  };
33
- export declare type ResponseObjectProof = {
33
+ export type ResponseObjectProof = {
34
34
  hash: Buffer;
35
35
  blockHeader: Buffer;
36
36
  signatures: BufferSignerPair[];
@@ -42,20 +42,20 @@ export declare enum ResponseStatus {
42
42
  Unknown = "unknown",
43
43
  Waiting = "waiting"
44
44
  }
45
- export declare type TransactionObject = {
45
+ export type TransactionObject = {
46
46
  tx: string;
47
47
  };
48
- export declare type StatusObject = {
48
+ export type StatusObject = {
49
49
  status: ResponseStatus;
50
50
  rejectReason?: string;
51
51
  };
52
- export declare type PostRequestObjects = TransactionObject | QueryObject;
53
- export declare type GetResponseObjects = StatusObject | TransactionObject | ServerReturnProof;
54
- export declare type FailOverConfig = {
52
+ export type PostRequestObjects = TransactionObject | QueryObject;
53
+ export type GetResponseObjects = StatusObject | TransactionObject | ServerReturnProof;
54
+ export type FailOverConfig = {
55
55
  attemptsPerEndpoint?: number;
56
56
  attemptInterval?: number;
57
57
  };
58
- export declare type ResponseObject = {
58
+ export type ResponseObject = {
59
59
  error: Error;
60
60
  statusCode: number;
61
61
  rspBody: any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "postchain-client",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Client library for accessing a Postchain node through REST.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -29,8 +29,7 @@
29
29
  "dependencies": {
30
30
  "@types/node": "^18.8.5",
31
31
  "asn1.js": "^4.10.1",
32
- "browser-request": "^0.3.3",
33
- "request": "^2.81.0",
32
+ "node-fetch": "^2.6.7",
34
33
  "secp256k1": "^4.0.3",
35
34
  "ts-loader": "^8.4.0"
36
35
  },
@@ -53,6 +52,7 @@
53
52
  "body-parser": "^1.17.1",
54
53
  "chai": "^3.5.0",
55
54
  "chai-as-promised": "^7.1.1",
55
+ "dotenv": "^16.0.3",
56
56
  "eslint": "^8.29.0",
57
57
  "eslint-config-prettier": "^8.5.0",
58
58
  "express": "^4.15.2",