@astrox/agent 0.0.16 → 0.0.24

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. package/package.json +4 -4
  2. package/lib/cjs/actor.d.ts +0 -126
  3. package/lib/cjs/actor.js +0 -207
  4. package/lib/cjs/actor.js.map +0 -1
  5. package/lib/cjs/agent/api.d.ts +0 -140
  6. package/lib/cjs/agent/api.js +0 -16
  7. package/lib/cjs/agent/api.js.map +0 -1
  8. package/lib/cjs/agent/http/index.d.ts +0 -49
  9. package/lib/cjs/agent/http/index.js +0 -355
  10. package/lib/cjs/agent/http/index.js.map +0 -1
  11. package/lib/cjs/agent/http/transforms.d.ts +0 -20
  12. package/lib/cjs/agent/http/transforms.js +0 -70
  13. package/lib/cjs/agent/http/transforms.js.map +0 -1
  14. package/lib/cjs/agent/http/types.d.ts +0 -77
  15. package/lib/cjs/agent/http/types.js +0 -24
  16. package/lib/cjs/agent/http/types.js.map +0 -1
  17. package/lib/cjs/agent/index.d.ts +0 -7
  18. package/lib/cjs/agent/index.js +0 -42
  19. package/lib/cjs/agent/index.js.map +0 -1
  20. package/lib/cjs/agent/proxy.d.ts +0 -85
  21. package/lib/cjs/agent/proxy.js +0 -159
  22. package/lib/cjs/agent/proxy.js.map +0 -1
  23. package/lib/cjs/auth.d.ts +0 -87
  24. package/lib/cjs/auth.js +0 -70
  25. package/lib/cjs/auth.js.map +0 -1
  26. package/lib/cjs/canisters/asset.d.ts +0 -10
  27. package/lib/cjs/canisters/asset.js +0 -18
  28. package/lib/cjs/canisters/asset.js.map +0 -1
  29. package/lib/cjs/canisters/asset_idl.d.ts +0 -7
  30. package/lib/cjs/canisters/asset_idl.js +0 -14
  31. package/lib/cjs/canisters/asset_idl.js.map +0 -1
  32. package/lib/cjs/canisters/management.d.ts +0 -33
  33. package/lib/cjs/canisters/management.js +0 -30
  34. package/lib/cjs/canisters/management.js.map +0 -1
  35. package/lib/cjs/canisters/management_idl.d.ts +0 -7
  36. package/lib/cjs/canisters/management_idl.js +0 -29
  37. package/lib/cjs/canisters/management_idl.js.map +0 -1
  38. package/lib/cjs/cbor.d.ts +0 -9
  39. package/lib/cjs/cbor.js +0 -138
  40. package/lib/cjs/cbor.js.map +0 -1
  41. package/lib/cjs/certificate.d.ts +0 -43
  42. package/lib/cjs/certificate.js +0 -227
  43. package/lib/cjs/certificate.js.map +0 -1
  44. package/lib/cjs/errors.d.ts +0 -8
  45. package/lib/cjs/errors.js +0 -13
  46. package/lib/cjs/errors.js.map +0 -1
  47. package/lib/cjs/index.d.ts +0 -52
  48. package/lib/cjs/index.js +0 -38
  49. package/lib/cjs/index.js.map +0 -1
  50. package/lib/cjs/polling/index.d.ts +0 -16
  51. package/lib/cjs/polling/index.js +0 -81
  52. package/lib/cjs/polling/index.js.map +0 -1
  53. package/lib/cjs/polling/strategy.d.ts +0 -47
  54. package/lib/cjs/polling/strategy.js +0 -106
  55. package/lib/cjs/polling/strategy.js.map +0 -1
  56. package/lib/cjs/request_id.d.ts +0 -15
  57. package/lib/cjs/request_id.js +0 -89
  58. package/lib/cjs/request_id.js.map +0 -1
  59. package/lib/cjs/utils/bls.d.ts +0 -9
  60. package/lib/cjs/utils/bls.js +0 -65
  61. package/lib/cjs/utils/bls.js.map +0 -1
  62. package/lib/cjs/utils/buffer.d.ts +0 -16
  63. package/lib/cjs/utils/buffer.js +0 -59
  64. package/lib/cjs/utils/buffer.js.map +0 -1
  65. package/lib/cjs/vendor/bls/bls.d.ts +0 -28
  66. package/lib/cjs/vendor/bls/bls.js +0 -894
  67. package/lib/cjs/vendor/bls/bls.js.map +0 -1
  68. package/lib/esm/actor.d.ts +0 -126
  69. package/lib/esm/actor.js +0 -200
  70. package/lib/esm/actor.js.map +0 -1
  71. package/lib/esm/agent/api.d.ts +0 -140
  72. package/lib/esm/agent/api.js +0 -13
  73. package/lib/esm/agent/api.js.map +0 -1
  74. package/lib/esm/agent/http/index.d.ts +0 -49
  75. package/lib/esm/agent/http/index.js +0 -328
  76. package/lib/esm/agent/http/index.js.map +0 -1
  77. package/lib/esm/agent/http/transforms.d.ts +0 -20
  78. package/lib/esm/agent/http/transforms.js +0 -45
  79. package/lib/esm/agent/http/transforms.js.map +0 -1
  80. package/lib/esm/agent/http/types.d.ts +0 -77
  81. package/lib/esm/agent/http/types.js +0 -20
  82. package/lib/esm/agent/http/types.js.map +0 -1
  83. package/lib/esm/agent/index.d.ts +0 -7
  84. package/lib/esm/agent/index.js +0 -27
  85. package/lib/esm/agent/index.js.map +0 -1
  86. package/lib/esm/agent/proxy.d.ts +0 -85
  87. package/lib/esm/agent/proxy.js +0 -154
  88. package/lib/esm/agent/proxy.js.map +0 -1
  89. package/lib/esm/auth.d.ts +0 -87
  90. package/lib/esm/auth.js +0 -64
  91. package/lib/esm/auth.js.map +0 -1
  92. package/lib/esm/canisters/asset.d.ts +0 -10
  93. package/lib/esm/canisters/asset.js +0 -11
  94. package/lib/esm/canisters/asset.js.map +0 -1
  95. package/lib/esm/canisters/asset_idl.d.ts +0 -7
  96. package/lib/esm/canisters/asset_idl.js +0 -12
  97. package/lib/esm/canisters/asset_idl.js.map +0 -1
  98. package/lib/esm/canisters/management.d.ts +0 -37
  99. package/lib/esm/canisters/management.js +0 -23
  100. package/lib/esm/canisters/management.js.map +0 -1
  101. package/lib/esm/canisters/management_idl.d.ts +0 -7
  102. package/lib/esm/canisters/management_idl.js +0 -27
  103. package/lib/esm/canisters/management_idl.js.map +0 -1
  104. package/lib/esm/cbor.d.ts +0 -9
  105. package/lib/esm/cbor.js +0 -111
  106. package/lib/esm/cbor.js.map +0 -1
  107. package/lib/esm/certificate.d.ts +0 -43
  108. package/lib/esm/certificate.js +0 -200
  109. package/lib/esm/certificate.js.map +0 -1
  110. package/lib/esm/errors.d.ts +0 -8
  111. package/lib/esm/errors.js +0 -9
  112. package/lib/esm/errors.js.map +0 -1
  113. package/lib/esm/index.d.ts +0 -52
  114. package/lib/esm/index.js +0 -14
  115. package/lib/esm/index.js.map +0 -1
  116. package/lib/esm/polling/index.d.ts +0 -16
  117. package/lib/esm/polling/index.js +0 -57
  118. package/lib/esm/polling/index.js.map +0 -1
  119. package/lib/esm/polling/strategy.d.ts +0 -47
  120. package/lib/esm/polling/strategy.js +0 -95
  121. package/lib/esm/polling/strategy.js.map +0 -1
  122. package/lib/esm/request_id.d.ts +0 -15
  123. package/lib/esm/request_id.js +0 -81
  124. package/lib/esm/request_id.js.map +0 -1
  125. package/lib/esm/utils/bls.d.ts +0 -9
  126. package/lib/esm/utils/bls.js +0 -43
  127. package/lib/esm/utils/bls.js.map +0 -1
  128. package/lib/esm/utils/buffer.d.ts +0 -16
  129. package/lib/esm/utils/buffer.js +0 -52
  130. package/lib/esm/utils/buffer.js.map +0 -1
  131. package/lib/esm/vendor/bls/bls.d.ts +0 -28
  132. package/lib/esm/vendor/bls/bls.js +0 -870
  133. package/lib/esm/vendor/bls/bls.js.map +0 -1
@@ -1,47 +0,0 @@
1
- import { Principal } from '@astrox/principal';
2
- import { RequestId, RequestStatusResponseStatus } from '..';
3
- import { PollStrategy } from './index';
4
- export declare type Predicate<T> = (canisterId: Principal, requestId: RequestId, status: RequestStatusResponseStatus) => Promise<T>;
5
- /**
6
- * A best practices polling strategy: wait 2 seconds before the first poll, then 1 second
7
- * with an exponential backoff factor of 1.2. Timeout after 5 minutes.
8
- */
9
- export declare function defaultStrategy(): PollStrategy;
10
- /**
11
- * Predicate that returns true once.
12
- */
13
- export declare function once(): Predicate<boolean>;
14
- /**
15
- * Delay the polling once.
16
- * @param condition A predicate that indicates when to delay.
17
- * @param timeInMsec The amount of time to delay.
18
- */
19
- export declare function conditionalDelay(condition: Predicate<boolean>, timeInMsec: number): PollStrategy;
20
- /**
21
- * Error out after a maximum number of polling has been done.
22
- * @param count The maximum attempts to poll.
23
- */
24
- export declare function maxAttempts(count: number): PollStrategy;
25
- /**
26
- * Throttle polling.
27
- * @param throttleInMsec Amount in millisecond to wait between each polling.
28
- */
29
- export declare function throttle(throttleInMsec: number): PollStrategy;
30
- /**
31
- * Reject a call after a certain amount of time.
32
- * @param timeInMsec Time in milliseconds before the polling should be rejected.
33
- */
34
- export declare function timeout(timeInMsec: number): PollStrategy;
35
- /**
36
- * A strategy that throttle, but using an exponential backoff strategy.
37
- * @param startingThrottleInMsec The throttle in milliseconds to start with.
38
- * @param backoffFactor The factor to multiple the throttle time between every poll. For
39
- * example if using 2, the throttle will double between every run.
40
- */
41
- export declare function backoff(startingThrottleInMsec: number, backoffFactor: number): PollStrategy;
42
- /**
43
- * Chain multiple polling strategy. This _chains_ the strategies, so if you pass in,
44
- * say, two throttling strategy of 1 second, it will result in a throttle of 2 seconds.
45
- * @param strategies A strategy list to chain.
46
- */
47
- export declare function chain(...strategies: PollStrategy[]): PollStrategy;
@@ -1,106 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.chain = exports.backoff = exports.timeout = exports.throttle = exports.maxAttempts = exports.conditionalDelay = exports.once = exports.defaultStrategy = void 0;
4
- const buffer_1 = require("../utils/buffer");
5
- const FIVE_MINUTES_IN_MSEC = 5 * 60 * 1000;
6
- /**
7
- * A best practices polling strategy: wait 2 seconds before the first poll, then 1 second
8
- * with an exponential backoff factor of 1.2. Timeout after 5 minutes.
9
- */
10
- function defaultStrategy() {
11
- return chain(conditionalDelay(once(), 1000), backoff(1000, 1.2), timeout(FIVE_MINUTES_IN_MSEC));
12
- }
13
- exports.defaultStrategy = defaultStrategy;
14
- /**
15
- * Predicate that returns true once.
16
- */
17
- function once() {
18
- let first = true;
19
- return async () => {
20
- if (first) {
21
- first = false;
22
- return true;
23
- }
24
- return false;
25
- };
26
- }
27
- exports.once = once;
28
- /**
29
- * Delay the polling once.
30
- * @param condition A predicate that indicates when to delay.
31
- * @param timeInMsec The amount of time to delay.
32
- */
33
- function conditionalDelay(condition, timeInMsec) {
34
- return async (canisterId, requestId, status) => {
35
- if (await condition(canisterId, requestId, status)) {
36
- return new Promise(resolve => setTimeout(resolve, timeInMsec));
37
- }
38
- };
39
- }
40
- exports.conditionalDelay = conditionalDelay;
41
- /**
42
- * Error out after a maximum number of polling has been done.
43
- * @param count The maximum attempts to poll.
44
- */
45
- function maxAttempts(count) {
46
- let attempts = count;
47
- return async (canisterId, requestId, status) => {
48
- if (--attempts <= 0) {
49
- throw new Error(`Failed to retrieve a reply for request after ${count} attempts:\n` +
50
- ` Request ID: ${buffer_1.toHex(requestId)}\n` +
51
- ` Request status: ${status}\n`);
52
- }
53
- };
54
- }
55
- exports.maxAttempts = maxAttempts;
56
- /**
57
- * Throttle polling.
58
- * @param throttleInMsec Amount in millisecond to wait between each polling.
59
- */
60
- function throttle(throttleInMsec) {
61
- return () => new Promise(resolve => setTimeout(resolve, throttleInMsec));
62
- }
63
- exports.throttle = throttle;
64
- /**
65
- * Reject a call after a certain amount of time.
66
- * @param timeInMsec Time in milliseconds before the polling should be rejected.
67
- */
68
- function timeout(timeInMsec) {
69
- const end = Date.now() + timeInMsec;
70
- return async (canisterId, requestId, status) => {
71
- if (Date.now() > end) {
72
- throw new Error(`Request timed out after ${timeInMsec} msec:\n` +
73
- ` Request ID: ${buffer_1.toHex(requestId)}\n` +
74
- ` Request status: ${status}\n`);
75
- }
76
- };
77
- }
78
- exports.timeout = timeout;
79
- /**
80
- * A strategy that throttle, but using an exponential backoff strategy.
81
- * @param startingThrottleInMsec The throttle in milliseconds to start with.
82
- * @param backoffFactor The factor to multiple the throttle time between every poll. For
83
- * example if using 2, the throttle will double between every run.
84
- */
85
- function backoff(startingThrottleInMsec, backoffFactor) {
86
- let currentThrottling = startingThrottleInMsec;
87
- return () => new Promise(resolve => setTimeout(() => {
88
- currentThrottling *= backoffFactor;
89
- resolve();
90
- }, currentThrottling));
91
- }
92
- exports.backoff = backoff;
93
- /**
94
- * Chain multiple polling strategy. This _chains_ the strategies, so if you pass in,
95
- * say, two throttling strategy of 1 second, it will result in a throttle of 2 seconds.
96
- * @param strategies A strategy list to chain.
97
- */
98
- function chain(...strategies) {
99
- return async (canisterId, requestId, status) => {
100
- for (const a of strategies) {
101
- await a(canisterId, requestId, status);
102
- }
103
- };
104
- }
105
- exports.chain = chain;
106
- //# sourceMappingURL=strategy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"strategy.js","sourceRoot":"","sources":["../../../src/polling/strategy.ts"],"names":[],"mappings":";;;AAEA,4CAAwC;AASxC,MAAM,oBAAoB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AAE3C;;;GAGG;AACH,SAAgB,eAAe;IAC7B,OAAO,KAAK,CAAC,gBAAgB,CAAC,IAAI,EAAE,EAAE,IAAI,CAAC,EAAE,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAC,CAAC;AAClG,CAAC;AAFD,0CAEC;AAED;;GAEG;AACH,SAAgB,IAAI;IAClB,IAAI,KAAK,GAAG,IAAI,CAAC;IACjB,OAAO,KAAK,IAAI,EAAE;QAChB,IAAI,KAAK,EAAE;YACT,KAAK,GAAG,KAAK,CAAC;YACd,OAAO,IAAI,CAAC;SACb;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;AACJ,CAAC;AATD,oBASC;AAED;;;;GAIG;AACH,SAAgB,gBAAgB,CAAC,SAA6B,EAAE,UAAkB;IAChF,OAAO,KAAK,EACV,UAAqB,EACrB,SAAoB,EACpB,MAAmC,EACnC,EAAE;QACF,IAAI,MAAM,SAAS,CAAC,UAAU,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE;YAClD,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC;SAChE;IACH,CAAC,CAAC;AACJ,CAAC;AAVD,4CAUC;AAED;;;GAGG;AACH,SAAgB,WAAW,CAAC,KAAa;IACvC,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,OAAO,KAAK,EACV,UAAqB,EACrB,SAAoB,EACpB,MAAmC,EACnC,EAAE;QACF,IAAI,EAAE,QAAQ,IAAI,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C,EACnC,EAAE;QACF,KAAK,MAAM,CAAC,IAAI,UAAU,EAAE;YAC1B,MAAM,CAAC,CAAC,UAAU,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;SACxC;IACH,CAAC,CAAC;AACJ,CAAC;AAVD,sBAUC"}
@@ -1,15 +0,0 @@
1
- export declare type RequestId = ArrayBuffer & {
2
- __requestId__: void;
3
- };
4
- /**
5
- * sha256 hash the provided Buffer
6
- * @param data - input to hash function
7
- */
8
- export declare function hash(data: ArrayBuffer): ArrayBuffer;
9
- /**
10
- * Get the RequestId of the provided ic-ref request.
11
- * RequestId is the result of the representation-independent-hash function.
12
- * https://sdk.dfinity.org/docs/interface-spec/index.html#hash-of-map
13
- * @param request - ic-ref request to hash into RequestId
14
- */
15
- export declare function requestIdOf(request: Record<string, any>): RequestId;
@@ -1,89 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.requestIdOf = exports.hash = void 0;
7
- const candid_1 = require("@astrox/candid");
8
- const principal_1 = require("@astrox/principal");
9
- const borc_1 = __importDefault(require("borc"));
10
- const js_sha256_1 = require("js-sha256");
11
- const buffer_1 = require("./utils/buffer");
12
- /**
13
- * sha256 hash the provided Buffer
14
- * @param data - input to hash function
15
- */
16
- function hash(data) {
17
- return js_sha256_1.sha256.create().update(new Uint8Array(data)).arrayBuffer();
18
- }
19
- exports.hash = hash;
20
- function hashValue(value) {
21
- if (value instanceof borc_1.default.Tagged) {
22
- return hashValue(value.value);
23
- }
24
- else if (typeof value === 'string') {
25
- return hashString(value);
26
- }
27
- else if (typeof value === 'number') {
28
- return hash(candid_1.lebEncode(value));
29
- }
30
- else if (value instanceof ArrayBuffer || ArrayBuffer.isView(value)) {
31
- return hash(value);
32
- }
33
- else if (Array.isArray(value)) {
34
- const vals = value.map(hashValue);
35
- return hash(buffer_1.concat(...vals));
36
- }
37
- else if (value instanceof principal_1.Principal) {
38
- return hash(value.toUint8Array());
39
- }
40
- else if (typeof value === 'object' &&
41
- value !== null &&
42
- typeof value.toHash === 'function') {
43
- return hashValue(value.toHash());
44
- // TODO This should be move to a specific async method as the webauthn flow required
45
- // the flow to be synchronous to ensure Safari touch id works.
46
- // } else if (value instanceof Promise) {
47
- // return value.then(x => hashValue(x));
48
- }
49
- else if (typeof value === 'bigint') {
50
- // Do this check much later than the other bigint check because this one is much less
51
- // type-safe.
52
- // So we want to try all the high-assurance type guards before this 'probable' one.
53
- return hash(candid_1.lebEncode(value));
54
- }
55
- throw Object.assign(new Error(`Attempt to hash a value of unsupported type: ${value}`), {
56
- // include so logs/callers can understand the confusing value.
57
- // (when stringified in error message, prototype info is lost)
58
- value,
59
- });
60
- }
61
- const hashString = (value) => {
62
- const encoded = new TextEncoder().encode(value);
63
- return hash(encoded);
64
- };
65
- /**
66
- * Get the RequestId of the provided ic-ref request.
67
- * RequestId is the result of the representation-independent-hash function.
68
- * https://sdk.dfinity.org/docs/interface-spec/index.html#hash-of-map
69
- * @param request - ic-ref request to hash into RequestId
70
- */
71
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
72
- function requestIdOf(request) {
73
- const hashed = Object.entries(request)
74
- .filter(([, value]) => value !== undefined)
75
- .map(([key, value]) => {
76
- const hashedKey = hashString(key);
77
- const hashedValue = hashValue(value);
78
- return [hashedKey, hashedValue];
79
- });
80
- const traversed = hashed;
81
- const sorted = traversed.sort(([k1], [k2]) => {
82
- return buffer_1.compare(k1, k2);
83
- });
84
- const concatenated = buffer_1.concat(...sorted.map(x => buffer_1.concat(...x)));
85
- const requestId = hash(concatenated);
86
- return requestId;
87
- }
88
- exports.requestIdOf = requestIdOf;
89
- //# sourceMappingURL=request_id.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"request_id.js","sourceRoot":"","sources":["../../src/request_id.ts"],"names":[],"mappings":";;;;;;AAAA,2CAA2C;AAC3C,iDAA8C;AAC9C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G,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,eAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3E,MAAM,SAAS,GAAG,IAAI,CAAC,YAAY,CAAc,CAAC;IAClD,OAAO,SAAS,CAAC;AACnB,CAAC;AAnBD,kCAmBC"}
@@ -1,9 +0,0 @@
1
- export declare let verify: (pk: Uint8Array, sig: Uint8Array, msg: Uint8Array) => Promise<boolean>;
2
- /**
3
- *
4
- * @param pk primary key: Uint8Array
5
- * @param sig signature: Uint8Array
6
- * @param msg message: Uint8Array
7
- * @returns Promise resolving a boolean
8
- */
9
- export declare function blsVerify(pk: Uint8Array, sig: Uint8Array, msg: Uint8Array): Promise<boolean>;
@@ -1,65 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.blsVerify = exports.verify = void 0;
23
- const index_1 = require("../index");
24
- const bls_1 = __importStar(require("../vendor/bls/bls"));
25
- /**
26
- *
27
- * @param pk primary key: Uint8Array
28
- * @param sig signature: Uint8Array
29
- * @param msg message: Uint8Array
30
- * @returns Promise resolving a boolean
31
- */
32
- async function blsVerify(pk, sig, msg) {
33
- if (!exports.verify) {
34
- const kraken = index_1.getKraken();
35
- if (!kraken) {
36
- await bls_1.default();
37
- if (bls_1.bls_init() !== 0) {
38
- throw new Error('Cannot initialize BLS');
39
- }
40
- exports.verify = async (pk1, sig1, msg1) => {
41
- // Reorder things from what the WASM expects (sig, m, w).
42
- return bls_1.bls_verify(sig1, msg1, pk1) === 0;
43
- };
44
- }
45
- else {
46
- const isInit = await kraken.methodChannel.invokeMethod('agent/blsInit', []);
47
- if (!isInit) {
48
- throw new Error('Cannot initialize BLS');
49
- }
50
- exports.verify = async (pk1, sig1, msg1) => {
51
- // Reorder things from what the WASM expects (sig, m, w).
52
- const verifyResult = await kraken.methodChannel.invokeMethod('agent/blsVerify', [
53
- Buffer.from(pk1).toString('hex'),
54
- Buffer.from(sig1).toString('hex'),
55
- new TextDecoder().decode(msg1),
56
- ]);
57
- return verifyResult === 0;
58
- };
59
- }
60
- }
61
- const result = await exports.verify(pk, sig, msg);
62
- return result;
63
- }
64
- exports.blsVerify = blsVerify;
65
- //# sourceMappingURL=bls.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"bls.js","sourceRoot":"","sources":["../../../src/utils/bls.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AACA,oCAAqC;AACrC,yDAA+D;AAI/D;;;;;;GAMG;AACI,KAAK,UAAU,SAAS,CAC7B,EAAc,EACd,GAAe,EACf,GAAe;IAEf,IAAI,CAAC,cAAM,EAAE;QACX,MAAM,MAAM,GAAG,iBAAS,EAAE,CAAC;QAE3B,IAAI,CAAC,MAAM,EAAE;YACX,MAAM,aAAI,EAAE,CAAC;YACb,IAAI,cAAQ,EAAE,KAAK,CAAC,EAAE;gBACpB,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;aAC1C;YACD,cAAM,GAAG,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE;gBACjC,yDAAyD;gBACzD,OAAO,gBAAU,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC;YAC3C,CAAC,CAAC;SACH;aAAM;YACL,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,YAAY,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC;YAC5E,IAAI,CAAC,MAAM,EAAE;gBACX,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;aAC1C;YACD,cAAM,GAAG,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE;gBACjC,yDAAyD;gBACzD,MAAM,YAAY,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,YAAY,CAAC,iBAAiB,EAAE;oBAC9E,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC;oBAChC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC;oBACjC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC;iBAC/B,CAAC,CAAC;gBACH,OAAO,YAAY,KAAK,CAAC,CAAC;YAC5B,CAAC,CAAC;SACH;KACF;IACD,MAAM,MAAM,GAAG,MAAM,cAAM,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IAC1C,OAAO,MAAM,CAAC;AAChB,CAAC;AAnCD,8BAmCC"}
@@ -1,16 +0,0 @@
1
- /**
2
- * Concatenate multiple array buffers.
3
- * @param buffers The buffers to concatenate.
4
- */
5
- export declare function concat(...buffers: ArrayBuffer[]): ArrayBuffer;
6
- /**
7
- * Transforms a buffer to an hexadecimal string. This will use the buffer as an Uint8Array.
8
- * @param buffer The buffer to return the hexadecimal string of.
9
- */
10
- export declare function toHex(buffer: ArrayBuffer): string;
11
- /**
12
- * Transforms a hexadecimal string into an array buffer.
13
- * @param hex The hexadecimal string to use.
14
- */
15
- export declare function fromHex(hex: string): ArrayBuffer;
16
- export declare function compare(b1: ArrayBuffer, b2: ArrayBuffer): number;
@@ -1,59 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.compare = exports.fromHex = exports.toHex = exports.concat = void 0;
4
- /**
5
- * Concatenate multiple array buffers.
6
- * @param buffers The buffers to concatenate.
7
- */
8
- function concat(...buffers) {
9
- const result = new Uint8Array(buffers.reduce((acc, curr) => acc + curr.byteLength, 0));
10
- let index = 0;
11
- for (const b of buffers) {
12
- result.set(new Uint8Array(b), index);
13
- index += b.byteLength;
14
- }
15
- return result.buffer;
16
- }
17
- exports.concat = concat;
18
- /**
19
- * Transforms a buffer to an hexadecimal string. This will use the buffer as an Uint8Array.
20
- * @param buffer The buffer to return the hexadecimal string of.
21
- */
22
- function toHex(buffer) {
23
- return [...new Uint8Array(buffer)].map(x => x.toString(16).padStart(2, '0')).join('');
24
- }
25
- exports.toHex = toHex;
26
- const hexRe = /^([0-9A-F]{2})*$/i.compile();
27
- /**
28
- * Transforms a hexadecimal string into an array buffer.
29
- * @param hex The hexadecimal string to use.
30
- */
31
- function fromHex(hex) {
32
- if (!hexRe.test(hex)) {
33
- throw new Error('Invalid hexadecimal string.');
34
- }
35
- const buffer = [...hex]
36
- .reduce((acc, curr, i) => {
37
- // tslint:disable-next-line:no-bitwise
38
- acc[(i / 2) | 0] = (acc[(i / 2) | 0] || '') + curr;
39
- return acc;
40
- }, [])
41
- .map(x => Number.parseInt(x, 16));
42
- return new Uint8Array(buffer).buffer;
43
- }
44
- exports.fromHex = fromHex;
45
- function compare(b1, b2) {
46
- if (b1.byteLength !== b2.byteLength) {
47
- return b1.byteLength - b2.byteLength;
48
- }
49
- const u1 = new Uint8Array(b1);
50
- const u2 = new Uint8Array(b2);
51
- for (let i = 0; i < u1.length; i++) {
52
- if (u1[i] !== u2[i]) {
53
- return u1[i] - u2[i];
54
- }
55
- }
56
- return 0;
57
- }
58
- exports.compare = compare;
59
- //# sourceMappingURL=buffer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"buffer.js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AG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;QACnD,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAAc,CAAC;SACjB,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IAEpC,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC;AACvC,CAAC;AAbD,0BAaC;AAED,SAAgB,OAAO,CAAC,EAAe,EAAE,EAAe;IACtD,IAAI,EAAE,CAAC,UAAU,KAAK,EAAE,CAAC,UAAU,EAAE;QACnC,OAAO,EAAE,CAAC,UAAU,GAAG,EAAE,CAAC,UAAU,CAAC;KACtC;IAED,MAAM,EAAE,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;IAC9B,MAAM,EAAE,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;IAC9B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QAClC,IAAI,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE;YACnB,OAAO,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC;SACtB;KACF;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AAbD,0BAaC"}
@@ -1,28 +0,0 @@
1
- /**
2
- * @returns {number}
3
- */
4
- export declare function bls_init(): number;
5
- /**
6
- * @param {Uint8Array} sig
7
- * @param {Uint8Array} m
8
- * @param {Uint8Array} w
9
- * @returns {number}
10
- */
11
- export declare function bls_verify(sig: Uint8Array, m: Uint8Array, w: Uint8Array): number;
12
- declare function init(): Promise<InitOutput>;
13
- export declare type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
14
- export interface InitOutput {
15
- readonly memory: WebAssembly.Memory;
16
- readonly bls_init: () => number;
17
- readonly bls_verify: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
18
- readonly __wbindgen_malloc: (a: number) => number;
19
- }
20
- /**
21
- * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
22
- * for everything else, calls `WebAssembly.instantiate` directly.
23
- *
24
- * @param {InitInput | Promise<InitInput>} module_or_path
25
- *
26
- * @returns {Promise<InitOutput>}
27
- */
28
- export default init;