@icp-sdk/core 5.0.0-beta.2 → 5.1.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/lib/cjs/agent/actor.d.ts +15 -1
- package/lib/cjs/agent/actor.d.ts.map +1 -1
- package/lib/cjs/agent/actor.js +37 -91
- package/lib/cjs/agent/actor.js.map +1 -1
- package/lib/cjs/agent/agent/api.d.ts +29 -6
- package/lib/cjs/agent/agent/api.d.ts.map +1 -1
- package/lib/cjs/agent/agent/api.js.map +1 -1
- package/lib/cjs/agent/agent/http/expiry.d.ts +36 -0
- package/lib/cjs/agent/agent/http/expiry.d.ts.map +1 -0
- package/lib/cjs/agent/agent/http/expiry.js +92 -0
- package/lib/cjs/agent/agent/http/expiry.js.map +1 -0
- package/lib/cjs/agent/agent/http/index.d.ts +11 -2
- package/lib/cjs/agent/agent/http/index.d.ts.map +1 -1
- package/lib/cjs/agent/agent/http/index.js +142 -73
- package/lib/cjs/agent/agent/http/index.js.map +1 -1
- package/lib/cjs/agent/agent/http/transforms.d.ts +1 -35
- package/lib/cjs/agent/agent/http/transforms.d.ts.map +1 -1
- package/lib/cjs/agent/agent/http/transforms.js +6 -90
- package/lib/cjs/agent/agent/http/transforms.js.map +1 -1
- package/lib/cjs/agent/agent/http/types.d.ts +1 -1
- package/lib/cjs/agent/agent/http/types.d.ts.map +1 -1
- package/lib/cjs/agent/auth.d.ts +1 -1
- package/lib/cjs/agent/auth.d.ts.map +1 -1
- package/lib/cjs/agent/canisterStatus/index.d.ts +5 -4
- package/lib/cjs/agent/canisterStatus/index.d.ts.map +1 -1
- package/lib/cjs/agent/canisterStatus/index.js +6 -10
- package/lib/cjs/agent/canisterStatus/index.js.map +1 -1
- package/lib/cjs/agent/cbor.js +2 -2
- package/lib/cjs/agent/cbor.js.map +1 -1
- package/lib/cjs/agent/certificate.d.ts +4 -4
- package/lib/cjs/agent/certificate.d.ts.map +1 -1
- package/lib/cjs/agent/certificate.js +6 -10
- package/lib/cjs/agent/certificate.js.map +1 -1
- package/lib/cjs/agent/constants.d.ts +4 -4
- package/lib/cjs/agent/constants.d.ts.map +1 -1
- package/lib/cjs/agent/der.d.ts.map +1 -1
- package/lib/cjs/agent/der.js +26 -21
- package/lib/cjs/agent/der.js.map +1 -1
- package/lib/cjs/agent/errors.d.ts +27 -18
- package/lib/cjs/agent/errors.d.ts.map +1 -1
- package/lib/cjs/agent/errors.js +18 -15
- package/lib/cjs/agent/errors.js.map +1 -1
- package/lib/cjs/agent/observable.d.ts +1 -1
- package/lib/cjs/agent/observable.d.ts.map +1 -1
- package/lib/cjs/agent/polling/backoff.d.ts +7 -7
- package/lib/cjs/agent/polling/backoff.d.ts.map +1 -1
- package/lib/cjs/agent/polling/backoff.js +3 -5
- package/lib/cjs/agent/polling/backoff.js.map +1 -1
- package/lib/cjs/agent/polling/index.d.ts +11 -10
- package/lib/cjs/agent/polling/index.d.ts.map +1 -1
- package/lib/cjs/agent/polling/index.js +8 -6
- package/lib/cjs/agent/polling/index.js.map +1 -1
- package/lib/cjs/agent/polling/strategy.d.ts +2 -5
- package/lib/cjs/agent/polling/strategy.d.ts.map +1 -1
- package/lib/cjs/agent/polling/strategy.js.map +1 -1
- package/lib/cjs/agent/polling/types.d.ts +18 -0
- package/lib/cjs/agent/polling/types.d.ts.map +1 -0
- package/lib/cjs/agent/polling/types.js +3 -0
- package/lib/cjs/agent/polling/types.js.map +1 -0
- package/lib/cjs/agent/public_key.d.ts +1 -1
- package/lib/cjs/agent/public_key.d.ts.map +1 -1
- package/lib/cjs/agent/request_id.d.ts.map +1 -1
- package/lib/cjs/agent/request_id.js +7 -7
- package/lib/cjs/agent/request_id.js.map +1 -1
- package/lib/cjs/agent/subnetStatus/index.d.ts +5 -4
- package/lib/cjs/agent/subnetStatus/index.d.ts.map +1 -1
- package/lib/cjs/agent/subnetStatus/index.js +6 -10
- package/lib/cjs/agent/subnetStatus/index.js.map +1 -1
- package/lib/cjs/agent/utils/buffer.d.ts.map +1 -1
- package/lib/cjs/agent/utils/buffer.js +4 -2
- package/lib/cjs/agent/utils/buffer.js.map +1 -1
- package/lib/cjs/agent/utils/certificateReject.d.ts +11 -0
- package/lib/cjs/agent/utils/certificateReject.d.ts.map +1 -0
- package/lib/cjs/agent/utils/certificateReject.js +19 -0
- package/lib/cjs/agent/utils/certificateReject.js.map +1 -0
- package/lib/cjs/agent/utils/expirableMap.d.ts +4 -4
- package/lib/cjs/agent/utils/expirableMap.d.ts.map +1 -1
- package/lib/cjs/agent/utils/expirableMap.js +2 -2
- package/lib/cjs/agent/utils/readState.d.ts +3 -3
- package/lib/cjs/agent/utils/readState.d.ts.map +1 -1
- package/lib/cjs/candid/candid-core.d.ts +1 -1
- package/lib/cjs/candid/candid-core.d.ts.map +1 -1
- package/lib/cjs/candid/candid-core.js +7 -9
- package/lib/cjs/candid/candid-core.js.map +1 -1
- package/lib/cjs/candid/candid-ui.d.ts.map +1 -1
- package/lib/cjs/candid/candid-ui.js +8 -24
- package/lib/cjs/candid/candid-ui.js.map +1 -1
- package/lib/cjs/candid/idl.d.ts +14 -1
- package/lib/cjs/candid/idl.d.ts.map +1 -1
- package/lib/cjs/candid/idl.js +164 -125
- package/lib/cjs/candid/idl.js.map +1 -1
- package/lib/cjs/candid/utils/leb128.d.ts.map +1 -1
- package/lib/cjs/candid/utils/leb128.js +1 -3
- package/lib/cjs/candid/utils/leb128.js.map +1 -1
- package/lib/cjs/identity/identity/delegation.d.ts +4 -3
- package/lib/cjs/identity/identity/delegation.d.ts.map +1 -1
- package/lib/cjs/identity/identity/delegation.js +3 -3
- package/lib/cjs/identity/identity/delegation.js.map +1 -1
- package/lib/cjs/identity/identity/ecdsa.d.ts +2 -2
- package/lib/cjs/identity/identity/ecdsa.d.ts.map +1 -1
- package/lib/cjs/identity/identity/ecdsa.js +2 -4
- package/lib/cjs/identity/identity/ecdsa.js.map +1 -1
- package/lib/cjs/identity/identity/ed25519.d.ts.map +1 -1
- package/lib/cjs/identity/identity/ed25519.js +9 -10
- package/lib/cjs/identity/identity/ed25519.js.map +1 -1
- package/lib/cjs/identity/identity/partial.d.ts +1 -1
- package/lib/cjs/identity/identity/partial.d.ts.map +1 -1
- package/lib/cjs/identity/identity/webauthn.js +4 -5
- package/lib/cjs/identity/identity/webauthn.js.map +1 -1
- package/lib/cjs/identity/secp256k1/der.d.ts.map +1 -1
- package/lib/cjs/identity/secp256k1/der.js +27 -22
- package/lib/cjs/identity/secp256k1/der.js.map +1 -1
- package/lib/cjs/identity/secp256k1/pem.js +1 -1
- package/lib/cjs/identity/secp256k1/pem.js.map +1 -1
- package/lib/cjs/identity/secp256k1/secp256k1.d.ts.map +1 -1
- package/lib/cjs/identity/secp256k1/secp256k1.js +6 -6
- package/lib/cjs/identity/secp256k1/secp256k1.js.map +1 -1
- package/lib/cjs/principal/principal.d.ts +2 -2
- package/lib/cjs/principal/principal.d.ts.map +1 -1
- package/lib/cjs/principal/principal.js +10 -6
- package/lib/cjs/principal/principal.js.map +1 -1
- package/lib/esm/agent/actor.d.ts +15 -1
- package/lib/esm/agent/actor.d.ts.map +1 -1
- package/lib/esm/agent/actor.js +40 -94
- package/lib/esm/agent/actor.js.map +1 -1
- package/lib/esm/agent/agent/api.d.ts +29 -6
- package/lib/esm/agent/agent/api.d.ts.map +1 -1
- package/lib/esm/agent/agent/api.js.map +1 -1
- package/lib/esm/agent/agent/http/expiry.d.ts +36 -0
- package/lib/esm/agent/agent/http/expiry.d.ts.map +1 -0
- package/lib/esm/agent/agent/http/expiry.js +88 -0
- package/lib/esm/agent/agent/http/expiry.js.map +1 -0
- package/lib/esm/agent/agent/http/index.d.ts +11 -2
- package/lib/esm/agent/agent/http/index.d.ts.map +1 -1
- package/lib/esm/agent/agent/http/index.js +145 -76
- package/lib/esm/agent/agent/http/index.js.map +1 -1
- package/lib/esm/agent/agent/http/transforms.d.ts +1 -35
- package/lib/esm/agent/agent/http/transforms.d.ts.map +1 -1
- package/lib/esm/agent/agent/http/transforms.js +2 -87
- package/lib/esm/agent/agent/http/transforms.js.map +1 -1
- package/lib/esm/agent/agent/http/types.d.ts +1 -1
- package/lib/esm/agent/agent/http/types.d.ts.map +1 -1
- package/lib/esm/agent/auth.d.ts +1 -1
- package/lib/esm/agent/auth.d.ts.map +1 -1
- package/lib/esm/agent/canister-env/index.d.ts +2 -2
- package/lib/esm/agent/canister-env/index.d.ts.map +1 -1
- package/lib/esm/agent/canisterStatus/index.d.ts +5 -4
- package/lib/esm/agent/canisterStatus/index.d.ts.map +1 -1
- package/lib/esm/agent/canisterStatus/index.js +6 -10
- package/lib/esm/agent/canisterStatus/index.js.map +1 -1
- package/lib/esm/agent/cbor.js +1 -1
- package/lib/esm/agent/cbor.js.map +1 -1
- package/lib/esm/agent/certificate.d.ts +4 -4
- package/lib/esm/agent/certificate.d.ts.map +1 -1
- package/lib/esm/agent/certificate.js +6 -10
- package/lib/esm/agent/certificate.js.map +1 -1
- package/lib/esm/agent/constants.d.ts +4 -4
- package/lib/esm/agent/constants.d.ts.map +1 -1
- package/lib/esm/agent/der.d.ts.map +1 -1
- package/lib/esm/agent/der.js +26 -21
- package/lib/esm/agent/der.js.map +1 -1
- package/lib/esm/agent/errors.d.ts +27 -18
- package/lib/esm/agent/errors.d.ts.map +1 -1
- package/lib/esm/agent/errors.js +16 -13
- package/lib/esm/agent/errors.js.map +1 -1
- package/lib/esm/agent/observable.d.ts +1 -1
- package/lib/esm/agent/observable.d.ts.map +1 -1
- package/lib/esm/agent/polling/backoff.d.ts +7 -7
- package/lib/esm/agent/polling/backoff.d.ts.map +1 -1
- package/lib/esm/agent/polling/backoff.js +3 -5
- package/lib/esm/agent/polling/backoff.js.map +1 -1
- package/lib/esm/agent/polling/index.d.ts +11 -10
- package/lib/esm/agent/polling/index.d.ts.map +1 -1
- package/lib/esm/agent/polling/index.js +9 -7
- package/lib/esm/agent/polling/index.js.map +1 -1
- package/lib/esm/agent/polling/strategy.d.ts +2 -5
- package/lib/esm/agent/polling/strategy.d.ts.map +1 -1
- package/lib/esm/agent/polling/strategy.js.map +1 -1
- package/lib/esm/agent/polling/types.d.ts +18 -0
- package/lib/esm/agent/polling/types.d.ts.map +1 -0
- package/lib/esm/agent/polling/types.js +2 -0
- package/lib/esm/agent/polling/types.js.map +1 -0
- package/lib/esm/agent/public_key.d.ts +1 -1
- package/lib/esm/agent/public_key.d.ts.map +1 -1
- package/lib/esm/agent/request_id.d.ts.map +1 -1
- package/lib/esm/agent/request_id.js +7 -7
- package/lib/esm/agent/request_id.js.map +1 -1
- package/lib/esm/agent/subnetStatus/index.d.ts +5 -4
- package/lib/esm/agent/subnetStatus/index.d.ts.map +1 -1
- package/lib/esm/agent/subnetStatus/index.js +6 -10
- package/lib/esm/agent/subnetStatus/index.js.map +1 -1
- package/lib/esm/agent/utils/buffer.d.ts.map +1 -1
- package/lib/esm/agent/utils/buffer.js +4 -2
- package/lib/esm/agent/utils/buffer.js.map +1 -1
- package/lib/esm/agent/utils/certificateReject.d.ts +11 -0
- package/lib/esm/agent/utils/certificateReject.d.ts.map +1 -0
- package/lib/esm/agent/utils/certificateReject.js +16 -0
- package/lib/esm/agent/utils/certificateReject.js.map +1 -0
- package/lib/esm/agent/utils/expirableMap.d.ts +4 -4
- package/lib/esm/agent/utils/expirableMap.d.ts.map +1 -1
- package/lib/esm/agent/utils/expirableMap.js +2 -2
- package/lib/esm/agent/utils/readState.d.ts +3 -3
- package/lib/esm/agent/utils/readState.d.ts.map +1 -1
- package/lib/esm/candid/candid-core.d.ts +1 -1
- package/lib/esm/candid/candid-core.d.ts.map +1 -1
- package/lib/esm/candid/candid-core.js +7 -9
- package/lib/esm/candid/candid-core.js.map +1 -1
- package/lib/esm/candid/candid-ui.d.ts.map +1 -1
- package/lib/esm/candid/candid-ui.js +7 -23
- package/lib/esm/candid/candid-ui.js.map +1 -1
- package/lib/esm/candid/idl.d.ts +14 -1
- package/lib/esm/candid/idl.d.ts.map +1 -1
- package/lib/esm/candid/idl.js +162 -124
- package/lib/esm/candid/idl.js.map +1 -1
- package/lib/esm/candid/utils/leb128.d.ts.map +1 -1
- package/lib/esm/candid/utils/leb128.js +1 -3
- package/lib/esm/candid/utils/leb128.js.map +1 -1
- package/lib/esm/identity/identity/delegation.d.ts +4 -3
- package/lib/esm/identity/identity/delegation.d.ts.map +1 -1
- package/lib/esm/identity/identity/delegation.js +3 -3
- package/lib/esm/identity/identity/delegation.js.map +1 -1
- package/lib/esm/identity/identity/ecdsa.d.ts +2 -2
- package/lib/esm/identity/identity/ecdsa.d.ts.map +1 -1
- package/lib/esm/identity/identity/ecdsa.js +2 -4
- package/lib/esm/identity/identity/ecdsa.js.map +1 -1
- package/lib/esm/identity/identity/ed25519.d.ts.map +1 -1
- package/lib/esm/identity/identity/ed25519.js +9 -10
- package/lib/esm/identity/identity/ed25519.js.map +1 -1
- package/lib/esm/identity/identity/partial.d.ts +1 -1
- package/lib/esm/identity/identity/partial.d.ts.map +1 -1
- package/lib/esm/identity/identity/webauthn.js +4 -5
- package/lib/esm/identity/identity/webauthn.js.map +1 -1
- package/lib/esm/identity/secp256k1/der.d.ts.map +1 -1
- package/lib/esm/identity/secp256k1/der.js +27 -22
- package/lib/esm/identity/secp256k1/der.js.map +1 -1
- package/lib/esm/identity/secp256k1/pem.js +1 -1
- package/lib/esm/identity/secp256k1/pem.js.map +1 -1
- package/lib/esm/identity/secp256k1/secp256k1.d.ts.map +1 -1
- package/lib/esm/identity/secp256k1/secp256k1.js +6 -6
- package/lib/esm/identity/secp256k1/secp256k1.js.map +1 -1
- package/lib/esm/principal/principal.d.ts +2 -2
- package/lib/esm/principal/principal.d.ts.map +1 -1
- package/lib/esm/principal/principal.js +10 -6
- package/lib/esm/principal/principal.js.map +1 -1
- package/package.json +13 -13
- package/src/agent/actor.ts +74 -126
- package/src/agent/agent/api.ts +36 -6
- package/src/agent/agent/http/expiry.ts +107 -0
- package/src/agent/agent/http/index.ts +217 -90
- package/src/agent/agent/http/transforms.ts +2 -106
- package/src/agent/agent/http/types.ts +1 -1
- package/src/agent/auth.ts +1 -1
- package/src/agent/canister-env/index.ts +2 -2
- package/src/agent/canisterStatus/index.ts +10 -12
- package/src/agent/cbor.ts +1 -1
- package/src/agent/certificate.ts +11 -13
- package/src/agent/der.ts +40 -19
- package/src/agent/errors.ts +41 -31
- package/src/agent/fetch_candid.ts +1 -1
- package/src/agent/observable.ts +1 -1
- package/src/agent/polling/backoff.ts +9 -10
- package/src/agent/polling/index.ts +14 -26
- package/src/agent/polling/strategy.ts +5 -9
- package/src/agent/polling/types.ts +28 -0
- package/src/agent/public_key.ts +1 -1
- package/src/agent/request_id.ts +15 -8
- package/src/agent/subnetStatus/index.ts +10 -12
- package/src/agent/utils/buffer.ts +6 -2
- package/src/agent/utils/certificateReject.ts +25 -0
- package/src/agent/utils/expirableMap.ts +4 -4
- package/src/agent/utils/random.ts +2 -2
- package/src/agent/utils/readState.ts +3 -3
- package/src/candid/candid-core.ts +9 -11
- package/src/candid/candid-ui.ts +8 -16
- package/src/candid/idl.ts +210 -112
- package/src/candid/utils/leb128.ts +1 -2
- package/src/identity/identity/delegation.ts +5 -5
- package/src/identity/identity/ecdsa.ts +12 -8
- package/src/identity/identity/ed25519.ts +16 -9
- package/src/identity/identity/partial.ts +1 -1
- package/src/identity/identity/webauthn.ts +21 -21
- package/src/identity/secp256k1/der.ts +41 -20
- package/src/identity/secp256k1/pem.ts +1 -1
- package/src/identity/secp256k1/secp256k1.ts +12 -6
- package/src/principal/principal.ts +18 -8
- package/LICENSE +0 -201
|
@@ -9,15 +9,15 @@ import {
|
|
|
9
9
|
InputError,
|
|
10
10
|
CertificateTimeErrorCode,
|
|
11
11
|
} from '../errors.ts';
|
|
12
|
-
import { HttpAgent } from '../agent/http/index.ts';
|
|
12
|
+
import type { HttpAgent } from '../agent/http/index.ts';
|
|
13
13
|
import { type Cert, Certificate, lookupResultToBuffer } from '../certificate.ts';
|
|
14
14
|
import * as cbor from '../cbor.ts';
|
|
15
15
|
import { decodeTime } from '../utils/leb.ts';
|
|
16
16
|
import { utf8ToBytes, bytesToHex } from '@noble/hashes/utils';
|
|
17
|
+
import type { CustomPath } from '../utils/readState.ts';
|
|
17
18
|
import {
|
|
18
19
|
type BaseSubnetStatus,
|
|
19
20
|
type BaseStatus,
|
|
20
|
-
CustomPath,
|
|
21
21
|
decodeValue,
|
|
22
22
|
decodeControllers,
|
|
23
23
|
encodeMetadataPath,
|
|
@@ -39,7 +39,7 @@ export type Path = 'time' | 'controllers' | 'subnet' | 'module_hash' | 'candid'
|
|
|
39
39
|
|
|
40
40
|
export type StatusMap = Map<Path | string, Status>;
|
|
41
41
|
|
|
42
|
-
export
|
|
42
|
+
export interface CanisterStatusOptions {
|
|
43
43
|
/**
|
|
44
44
|
* The effective canister ID to use in the underlying {@link HttpAgent.readState} call.
|
|
45
45
|
*/
|
|
@@ -58,7 +58,7 @@ export type CanisterStatusOptions = {
|
|
|
58
58
|
* @default false
|
|
59
59
|
*/
|
|
60
60
|
disableCertificateTimeVerification?: boolean;
|
|
61
|
-
}
|
|
61
|
+
}
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
64
|
* Requests information from a canister's `read_state` endpoint.
|
|
@@ -115,12 +115,11 @@ export const request = async (options: CanisterStatusOptions): Promise<StatusMap
|
|
|
115
115
|
path,
|
|
116
116
|
data,
|
|
117
117
|
};
|
|
118
|
-
} else {
|
|
119
|
-
return {
|
|
120
|
-
path,
|
|
121
|
-
data: lookupResultToBuffer(cert.lookup_path(encodedPath)),
|
|
122
|
-
};
|
|
123
118
|
}
|
|
119
|
+
return {
|
|
120
|
+
path,
|
|
121
|
+
data: lookupResultToBuffer(cert.lookup_path(encodedPath)),
|
|
122
|
+
};
|
|
124
123
|
};
|
|
125
124
|
|
|
126
125
|
// must pass in the rootKey if we have no delegation
|
|
@@ -247,10 +246,9 @@ export const encodePath = (path: Path, canisterId: Principal): Uint8Array[] => {
|
|
|
247
246
|
// For simplified metadata queries
|
|
248
247
|
if (typeof path['path'] === 'string' || path['path'] instanceof Uint8Array) {
|
|
249
248
|
return encodeMetadataPath(path.path, canisterUint8Array);
|
|
250
|
-
} else {
|
|
251
|
-
// For non-metadata, return the provided custom path
|
|
252
|
-
return path['path'];
|
|
253
249
|
}
|
|
250
|
+
// For non-metadata, return the provided custom path
|
|
251
|
+
return path['path'];
|
|
254
252
|
}
|
|
255
253
|
}
|
|
256
254
|
}
|
package/src/agent/cbor.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Principal } from '#principal';
|
|
2
2
|
import * as cbor from '@dfinity/cbor';
|
|
3
3
|
import { CborDecodeErrorCode, CborEncodeErrorCode, InputError } from './errors.ts';
|
|
4
|
-
import { Expiry } from './agent/
|
|
4
|
+
import { Expiry } from './agent/http/expiry.ts';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Used to extend classes that need to provide a custom value for the CBOR encoding process.
|
package/src/agent/certificate.ts
CHANGED
|
@@ -78,7 +78,7 @@ export function hashTreeToString(tree: HashTree): string {
|
|
|
78
78
|
const indent = (s: string) =>
|
|
79
79
|
s
|
|
80
80
|
.split('\n')
|
|
81
|
-
.map(x =>
|
|
81
|
+
.map(x => ` ${x}`)
|
|
82
82
|
.join('\n');
|
|
83
83
|
function labelToString(label: Uint8Array): string {
|
|
84
84
|
const decoder = new TextDecoder(undefined, { fatal: true });
|
|
@@ -94,24 +94,22 @@ export function hashTreeToString(tree: HashTree): string {
|
|
|
94
94
|
case NodeType.Empty:
|
|
95
95
|
return '()';
|
|
96
96
|
case NodeType.Fork: {
|
|
97
|
-
if (tree[1] instanceof Array && tree[2] instanceof
|
|
97
|
+
if (tree[1] instanceof Array && tree[2] instanceof Array) {
|
|
98
98
|
const left = hashTreeToString(tree[1]);
|
|
99
99
|
const right = hashTreeToString(tree[2]);
|
|
100
100
|
return `sub(\n left:\n${indent(left)}\n---\n right:\n${indent(right)}\n)`;
|
|
101
|
-
} else {
|
|
102
|
-
throw UnknownError.fromCode(new HashTreeDecodeErrorCode('Invalid tree structure for fork'));
|
|
103
101
|
}
|
|
102
|
+
throw UnknownError.fromCode(new HashTreeDecodeErrorCode('Invalid tree structure for fork'));
|
|
104
103
|
}
|
|
105
104
|
case NodeType.Labeled: {
|
|
106
|
-
if (tree[1] instanceof Uint8Array && tree[2] instanceof
|
|
105
|
+
if (tree[1] instanceof Uint8Array && tree[2] instanceof Array) {
|
|
107
106
|
const label = labelToString(tree[1]);
|
|
108
107
|
const sub = hashTreeToString(tree[2]);
|
|
109
108
|
return `label(\n label:\n${indent(label)}\n sub:\n${indent(sub)}\n)`;
|
|
110
|
-
} else {
|
|
111
|
-
throw UnknownError.fromCode(
|
|
112
|
-
new HashTreeDecodeErrorCode('Invalid tree structure for labeled'),
|
|
113
|
-
);
|
|
114
109
|
}
|
|
110
|
+
throw UnknownError.fromCode(
|
|
111
|
+
new HashTreeDecodeErrorCode('Invalid tree structure for labeled'),
|
|
112
|
+
);
|
|
115
113
|
}
|
|
116
114
|
case NodeType.Leaf: {
|
|
117
115
|
if (!tree[1]) {
|
|
@@ -184,7 +182,7 @@ export interface CreateCertificateOptions {
|
|
|
184
182
|
*/
|
|
185
183
|
principal: CertificatePrincipal;
|
|
186
184
|
/**
|
|
187
|
-
* BLS Verification strategy. Default strategy uses bls12_381 from
|
|
185
|
+
* BLS Verification strategy. Default strategy uses bls12_381 from `@noble/curves`
|
|
188
186
|
*/
|
|
189
187
|
blsVerify?: VerifyFunc;
|
|
190
188
|
|
|
@@ -221,7 +219,7 @@ export class Certificate {
|
|
|
221
219
|
/**
|
|
222
220
|
* Create a new instance of a certificate, automatically verifying it.
|
|
223
221
|
* @param {CreateCertificateOptions} options {@link CreateCertificateOptions}
|
|
224
|
-
* @throws if the verification of the certificate fails
|
|
222
|
+
* @throws {Error} if the verification of the certificate fails
|
|
225
223
|
*/
|
|
226
224
|
public static async create(options: CreateCertificateOptions): Promise<Certificate> {
|
|
227
225
|
const cert = Certificate.createUnverified(options);
|
|
@@ -875,11 +873,11 @@ function list_paths(path: Array<NodeLabel>, tree: HashTree): Array<Array<NodeLab
|
|
|
875
873
|
}
|
|
876
874
|
}
|
|
877
875
|
|
|
878
|
-
export
|
|
876
|
+
export interface CheckCanisterRangesParams {
|
|
879
877
|
canisterId: Principal;
|
|
880
878
|
subnetId: Principal;
|
|
881
879
|
tree: HashTree;
|
|
882
|
-
}
|
|
880
|
+
}
|
|
883
881
|
|
|
884
882
|
/**
|
|
885
883
|
* Canister ranges in the form of an array of [start, end] principal tuples,
|
package/src/agent/der.ts
CHANGED
|
@@ -9,57 +9,78 @@ import { uint8Equals } from './utils/buffer.ts';
|
|
|
9
9
|
export const encodeLenBytes = (len: number): number => {
|
|
10
10
|
if (len <= 0x7f) {
|
|
11
11
|
return 1;
|
|
12
|
-
}
|
|
12
|
+
}
|
|
13
|
+
if (len <= 0xff) {
|
|
13
14
|
return 2;
|
|
14
|
-
}
|
|
15
|
+
}
|
|
16
|
+
if (len <= 0xffff) {
|
|
15
17
|
return 3;
|
|
16
|
-
}
|
|
18
|
+
}
|
|
19
|
+
if (len <= 0xffffff) {
|
|
17
20
|
return 4;
|
|
18
|
-
} else {
|
|
19
|
-
throw InputError.fromCode(new DerEncodeErrorCode('Length too long (> 4 bytes)'));
|
|
20
21
|
}
|
|
22
|
+
throw InputError.fromCode(new DerEncodeErrorCode('Length too long (> 4 bytes)'));
|
|
21
23
|
};
|
|
22
24
|
|
|
23
25
|
export const encodeLen = (buf: Uint8Array, offset: number, len: number): number => {
|
|
24
26
|
if (len <= 0x7f) {
|
|
25
27
|
buf[offset] = len;
|
|
26
28
|
return 1;
|
|
27
|
-
}
|
|
29
|
+
}
|
|
30
|
+
if (len <= 0xff) {
|
|
28
31
|
buf[offset] = 0x81;
|
|
29
32
|
buf[offset + 1] = len;
|
|
30
33
|
return 2;
|
|
31
|
-
}
|
|
34
|
+
}
|
|
35
|
+
if (len <= 0xffff) {
|
|
32
36
|
buf[offset] = 0x82;
|
|
33
37
|
buf[offset + 1] = len >> 8;
|
|
34
38
|
buf[offset + 2] = len;
|
|
35
39
|
return 3;
|
|
36
|
-
}
|
|
40
|
+
}
|
|
41
|
+
if (len <= 0xffffff) {
|
|
37
42
|
buf[offset] = 0x83;
|
|
38
43
|
buf[offset + 1] = len >> 16;
|
|
39
44
|
buf[offset + 2] = len >> 8;
|
|
40
45
|
buf[offset + 3] = len;
|
|
41
46
|
return 4;
|
|
42
|
-
} else {
|
|
43
|
-
throw InputError.fromCode(new DerEncodeErrorCode('Length too long (> 4 bytes)'));
|
|
44
47
|
}
|
|
48
|
+
throw InputError.fromCode(new DerEncodeErrorCode('Length too long (> 4 bytes)'));
|
|
45
49
|
};
|
|
46
50
|
|
|
47
51
|
export const decodeLenBytes = (buf: Uint8Array, offset: number): number => {
|
|
48
|
-
if (buf[offset] < 0x80)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (buf[offset] ===
|
|
52
|
-
|
|
52
|
+
if (buf[offset] < 0x80) {
|
|
53
|
+
return 1;
|
|
54
|
+
}
|
|
55
|
+
if (buf[offset] === 0x80) {
|
|
56
|
+
throw InputError.fromCode(new DerDecodeErrorCode('Invalid length 0'));
|
|
57
|
+
}
|
|
58
|
+
if (buf[offset] === 0x81) {
|
|
59
|
+
return 2;
|
|
60
|
+
}
|
|
61
|
+
if (buf[offset] === 0x82) {
|
|
62
|
+
return 3;
|
|
63
|
+
}
|
|
64
|
+
if (buf[offset] === 0x83) {
|
|
65
|
+
return 4;
|
|
66
|
+
}
|
|
53
67
|
throw InputError.fromCode(new DerDecodeErrorCode('Length too long (> 4 bytes)'));
|
|
54
68
|
};
|
|
55
69
|
|
|
56
70
|
export const decodeLen = (buf: Uint8Array, offset: number): number => {
|
|
57
71
|
const lenBytes = decodeLenBytes(buf, offset);
|
|
58
|
-
if (lenBytes === 1)
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
72
|
+
if (lenBytes === 1) {
|
|
73
|
+
return buf[offset];
|
|
74
|
+
}
|
|
75
|
+
if (lenBytes === 2) {
|
|
76
|
+
return buf[offset + 1];
|
|
77
|
+
}
|
|
78
|
+
if (lenBytes === 3) {
|
|
79
|
+
return (buf[offset + 1] << 8) + buf[offset + 2];
|
|
80
|
+
}
|
|
81
|
+
if (lenBytes === 4) {
|
|
62
82
|
return (buf[offset + 1] << 16) + (buf[offset + 2] << 8) + buf[offset + 3];
|
|
83
|
+
}
|
|
63
84
|
throw InputError.fromCode(new DerDecodeErrorCode('Length too long (> 4 bytes)'));
|
|
64
85
|
};
|
|
65
86
|
|
package/src/agent/errors.ts
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import { Principal } from '#principal';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from './agent/
|
|
7
|
-
import {
|
|
8
|
-
import { type RequestStatusResponseStatus } from './agent/http/index.ts';
|
|
9
|
-
import { type Expiry } from './agent/http/transforms.ts';
|
|
10
|
-
import { type HttpHeaderField } from './agent/http/types.ts';
|
|
11
|
-
import { LookupPathStatus, LookupSubtreeStatus } from './certificate.ts';
|
|
1
|
+
import type { Principal } from '#principal';
|
|
2
|
+
import type { HttpDetailsResponse, NodeSignature, ReplicaRejectCode } from './agent/api.ts';
|
|
3
|
+
import type { RequestId } from './request_id.ts';
|
|
4
|
+
import type { RequestStatusResponseStatus } from './agent/http/index.ts';
|
|
5
|
+
import type { Expiry } from './agent/http/expiry.ts';
|
|
6
|
+
import type { HttpHeaderField } from './agent/http/types.ts';
|
|
7
|
+
import type { LookupPathStatus, LookupSubtreeStatus } from './certificate.ts';
|
|
12
8
|
import { bytesToHex } from '@noble/hashes/utils';
|
|
13
9
|
|
|
14
10
|
export enum ErrorKindEnum {
|
|
@@ -22,22 +18,31 @@ export enum ErrorKindEnum {
|
|
|
22
18
|
Unknown = 'Unknown',
|
|
23
19
|
}
|
|
24
20
|
|
|
25
|
-
export
|
|
21
|
+
export interface RequestContext {
|
|
26
22
|
requestId?: RequestId;
|
|
27
23
|
senderPubKey: Uint8Array;
|
|
28
24
|
senderSignature: Uint8Array;
|
|
29
25
|
ingressExpiry: Expiry;
|
|
30
|
-
}
|
|
26
|
+
}
|
|
31
27
|
|
|
32
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Call context for errors that arise during polling.
|
|
30
|
+
*/
|
|
31
|
+
export interface PollingCallContext {
|
|
33
32
|
canisterId: Principal;
|
|
34
33
|
methodName: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Call context for errors that arise from a direct HTTP call response.
|
|
38
|
+
*/
|
|
39
|
+
export interface CallContext extends PollingCallContext {
|
|
35
40
|
httpDetails: HttpDetailsResponse;
|
|
36
|
-
}
|
|
41
|
+
}
|
|
37
42
|
|
|
38
43
|
abstract class ErrorCode {
|
|
39
44
|
public requestContext?: RequestContext;
|
|
40
|
-
public callContext?: CallContext;
|
|
45
|
+
public callContext?: CallContext | PollingCallContext;
|
|
41
46
|
|
|
42
47
|
constructor(public readonly isCertified: boolean = false) {}
|
|
43
48
|
|
|
@@ -57,8 +62,10 @@ abstract class ErrorCode {
|
|
|
57
62
|
errorMessage +=
|
|
58
63
|
`\nCall context:\n` +
|
|
59
64
|
` Canister ID: ${this.callContext.canisterId.toText()}\n` +
|
|
60
|
-
` Method name: ${this.callContext.methodName}
|
|
61
|
-
|
|
65
|
+
` Method name: ${this.callContext.methodName}`;
|
|
66
|
+
if ('httpDetails' in this.callContext) {
|
|
67
|
+
errorMessage += `\n HTTP details: ${JSON.stringify(this.callContext.httpDetails, null, 2)}`;
|
|
68
|
+
}
|
|
62
69
|
}
|
|
63
70
|
return errorMessage;
|
|
64
71
|
}
|
|
@@ -598,19 +605,6 @@ export class HashValueErrorCode extends ErrorCode {
|
|
|
598
605
|
}
|
|
599
606
|
}
|
|
600
607
|
|
|
601
|
-
export class HttpDefaultFetchErrorCode extends ErrorCode {
|
|
602
|
-
public name = 'HttpDefaultFetchErrorCode';
|
|
603
|
-
|
|
604
|
-
constructor(public readonly error: string) {
|
|
605
|
-
super();
|
|
606
|
-
Object.setPrototypeOf(this, HttpDefaultFetchErrorCode.prototype);
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
public toErrorMessage(): string {
|
|
610
|
-
return this.error;
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
|
|
614
608
|
export class IdentityInvalidErrorCode extends ErrorCode {
|
|
615
609
|
public name = 'IdentityInvalidErrorCode';
|
|
616
610
|
|
|
@@ -653,6 +647,22 @@ export class CreateHttpAgentErrorCode extends ErrorCode {
|
|
|
653
647
|
}
|
|
654
648
|
}
|
|
655
649
|
|
|
650
|
+
export class ExcessiveSignaturesErrorCode extends ErrorCode {
|
|
651
|
+
public name = 'ExcessiveSignaturesErrorCode';
|
|
652
|
+
|
|
653
|
+
constructor(
|
|
654
|
+
public readonly signatureCount: number,
|
|
655
|
+
public readonly maxExpected: number,
|
|
656
|
+
) {
|
|
657
|
+
super();
|
|
658
|
+
Object.setPrototypeOf(this, ExcessiveSignaturesErrorCode.prototype);
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
public toErrorMessage(): string {
|
|
662
|
+
return `Query response contains ${this.signatureCount} signatures, which exceeds the subnet size of ${this.maxExpected}. This suggests a malformed or malicious response.`;
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
|
|
656
666
|
export class MalformedSignatureErrorCode extends ErrorCode {
|
|
657
667
|
public name = 'MalformedSignatureErrorCode';
|
|
658
668
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Principal } from '#principal';
|
|
2
2
|
import * as CanisterStatus from './canisterStatus/index.ts';
|
|
3
|
-
import { IDL } from '#candid';
|
|
3
|
+
import type { IDL } from '#candid';
|
|
4
4
|
import { HttpAgent } from './agent/http/index.ts';
|
|
5
5
|
import { Actor, type ActorSubclass } from './actor.ts';
|
|
6
6
|
|
package/src/agent/observable.ts
CHANGED
|
@@ -5,23 +5,23 @@ const MAX_INTERVAL_MSEC = 60_000;
|
|
|
5
5
|
const MAX_ELAPSED_TIME_MSEC = 900_000;
|
|
6
6
|
const MAX_ITERATIONS = 10;
|
|
7
7
|
|
|
8
|
-
export
|
|
8
|
+
export interface BackoffStrategy {
|
|
9
9
|
next: () => number | null;
|
|
10
10
|
currentInterval?: number;
|
|
11
11
|
count?: number;
|
|
12
12
|
ellapsedTimeInMsec?: number;
|
|
13
|
-
}
|
|
13
|
+
}
|
|
14
14
|
|
|
15
|
-
export
|
|
15
|
+
export interface BackoffStrategyArgs {
|
|
16
16
|
maxIterations?: number;
|
|
17
17
|
maxElapsedTime?: number;
|
|
18
|
-
}
|
|
18
|
+
}
|
|
19
19
|
|
|
20
20
|
export type BackoffStrategyFactory = (args?: BackoffStrategyArgs) => BackoffStrategy;
|
|
21
21
|
|
|
22
22
|
// export type BackoffStrategyGenerator = Generator<number, void, unknown>;
|
|
23
23
|
|
|
24
|
-
export
|
|
24
|
+
export interface ExponentialBackoffOptions {
|
|
25
25
|
initialInterval?: number;
|
|
26
26
|
randomizationFactor?: number;
|
|
27
27
|
multiplier?: number;
|
|
@@ -29,7 +29,7 @@ export type ExponentialBackoffOptions = {
|
|
|
29
29
|
maxElapsedTime?: number;
|
|
30
30
|
maxIterations?: number;
|
|
31
31
|
date?: DateConstructor;
|
|
32
|
-
}
|
|
32
|
+
}
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
* Exponential backoff strategy.
|
|
@@ -105,17 +105,16 @@ export class ExponentialBackoff {
|
|
|
105
105
|
public next() {
|
|
106
106
|
if (this.ellapsedTimeInMsec >= this.#maxElapsedTime || this.#count >= this.#maxIterations) {
|
|
107
107
|
return null;
|
|
108
|
-
} else {
|
|
109
|
-
this.incrementCurrentInterval();
|
|
110
|
-
return this.randomValueFromInterval;
|
|
111
108
|
}
|
|
109
|
+
this.incrementCurrentInterval();
|
|
110
|
+
return this.randomValueFromInterval;
|
|
112
111
|
}
|
|
113
112
|
}
|
|
114
113
|
/**
|
|
115
114
|
* Utility function to create an exponential backoff iterator.
|
|
116
115
|
* @param options - for the exponential backoff
|
|
117
116
|
* @returns an iterator that yields the next delay in the exponential backoff
|
|
118
|
-
* @yields the next delay in the exponential backoff
|
|
117
|
+
* @yields {number} the next delay in the exponential backoff
|
|
119
118
|
*/
|
|
120
119
|
export function* exponentialBackoff(
|
|
121
120
|
options: ExponentialBackoffOptions = ExponentialBackoff.default,
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { RequestId } from '../request_id.ts';
|
|
2
2
|
import {
|
|
3
3
|
type CreateCertificateOptions,
|
|
4
4
|
Certificate,
|
|
5
5
|
lookupResultToBuffer,
|
|
6
6
|
} from '../certificate.ts';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { readCertifiedReject } from '../utils/certificateReject.ts';
|
|
8
|
+
import type { Agent, ReadStateResponse } from '../agent/api.ts';
|
|
9
|
+
import type { Principal } from '#principal';
|
|
9
10
|
import {
|
|
10
|
-
CertifiedRejectErrorCode,
|
|
11
11
|
ExternalError,
|
|
12
12
|
InputError,
|
|
13
13
|
InvalidReadStateRequestErrorCode,
|
|
@@ -20,16 +20,12 @@ import {
|
|
|
20
20
|
|
|
21
21
|
export * as strategy from './strategy.ts';
|
|
22
22
|
import { defaultStrategy } from './strategy.ts';
|
|
23
|
+
import type { PollStrategy, PollForResponseResult } from './types.ts';
|
|
23
24
|
import { ReadRequestType, type ReadStateRequest } from '../agent/http/types.ts';
|
|
24
|
-
import { RequestStatusResponseStatus } from '../agent/index.ts';
|
|
25
|
+
import { RequestStatusResponseStatus } from '../agent/http/index.ts';
|
|
25
26
|
import { utf8ToBytes } from '@noble/hashes/utils';
|
|
26
27
|
export { defaultStrategy } from './strategy.ts';
|
|
27
|
-
|
|
28
|
-
export type PollStrategy = (
|
|
29
|
-
canisterId: Principal,
|
|
30
|
-
requestId: RequestId,
|
|
31
|
-
status: RequestStatusResponseStatus,
|
|
32
|
-
) => Promise<void>;
|
|
28
|
+
export type { PollStrategy, PollForResponseResult } from './types.ts';
|
|
33
29
|
|
|
34
30
|
interface SignedReadStateRequestWithExpiry extends ReadStateRequest {
|
|
35
31
|
body: {
|
|
@@ -122,16 +118,17 @@ function isSignedReadStateRequestWithExpiry(
|
|
|
122
118
|
* @param canisterId The effective canister ID.
|
|
123
119
|
* @param requestId The Request ID to poll status for.
|
|
124
120
|
* @param options polling options to control behavior
|
|
121
|
+
* @returns The certificate, reply bytes, and raw certificate bytes for the request.
|
|
122
|
+
* @throws {ExternalError} If the agent's root key is not available.
|
|
123
|
+
* @throws {RejectError} If the request was rejected by the canister.
|
|
124
|
+
* @throws {UnknownError} If the request reached `done` status without a reply.
|
|
125
125
|
*/
|
|
126
126
|
export async function pollForResponse(
|
|
127
127
|
agent: Agent,
|
|
128
128
|
canisterId: Principal,
|
|
129
129
|
requestId: RequestId,
|
|
130
130
|
options: PollingOptions = {},
|
|
131
|
-
): Promise<{
|
|
132
|
-
certificate: Certificate;
|
|
133
|
-
reply: Uint8Array;
|
|
134
|
-
}> {
|
|
131
|
+
): Promise<PollForResponseResult> {
|
|
135
132
|
const path = [utf8ToBytes('request_status'), requestId];
|
|
136
133
|
|
|
137
134
|
let state: ReadStateResponse;
|
|
@@ -175,6 +172,7 @@ export async function pollForResponse(
|
|
|
175
172
|
return {
|
|
176
173
|
reply: lookupResultToBuffer(cert.lookup_path([...path, 'reply']))!,
|
|
177
174
|
certificate: cert,
|
|
175
|
+
rawCertificate: state.certificate,
|
|
178
176
|
};
|
|
179
177
|
}
|
|
180
178
|
|
|
@@ -194,17 +192,7 @@ export async function pollForResponse(
|
|
|
194
192
|
}
|
|
195
193
|
|
|
196
194
|
case RequestStatusResponseStatus.Rejected: {
|
|
197
|
-
|
|
198
|
-
lookupResultToBuffer(cert.lookup_path([...path, 'reject_code']))!,
|
|
199
|
-
)[0];
|
|
200
|
-
const rejectMessage = new TextDecoder().decode(
|
|
201
|
-
lookupResultToBuffer(cert.lookup_path([...path, 'reject_message']))!,
|
|
202
|
-
);
|
|
203
|
-
const errorCodeBuf = lookupResultToBuffer(cert.lookup_path([...path, 'error_code']));
|
|
204
|
-
const errorCode = errorCodeBuf ? new TextDecoder().decode(errorCodeBuf) : undefined;
|
|
205
|
-
throw RejectError.fromCode(
|
|
206
|
-
new CertifiedRejectErrorCode(requestId, rejectCode, rejectMessage, errorCode),
|
|
207
|
-
);
|
|
195
|
+
throw RejectError.fromCode(readCertifiedReject(cert, path, requestId));
|
|
208
196
|
}
|
|
209
197
|
|
|
210
198
|
case RequestStatusResponseStatus.Done:
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import { Principal } from '#principal';
|
|
2
|
-
import { RequestStatusResponseStatus } from '../agent/index.ts';
|
|
3
|
-
import {
|
|
4
|
-
import { type RequestId } from '../request_id.ts';
|
|
1
|
+
import type { Principal } from '#principal';
|
|
2
|
+
import type { RequestStatusResponseStatus } from '../agent/http/index.ts';
|
|
3
|
+
import type { RequestId } from '../request_id.ts';
|
|
5
4
|
import { ProtocolError, TimeoutWaitingForResponseErrorCode } from '../errors.ts';
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
requestId: RequestId,
|
|
10
|
-
status: RequestStatusResponseStatus,
|
|
11
|
-
) => Promise<T>;
|
|
6
|
+
import type { PollStrategy, Predicate } from './types.ts';
|
|
7
|
+
export type { PollStrategy, Predicate } from './types.ts';
|
|
12
8
|
|
|
13
9
|
const FIVE_MINUTES_IN_MSEC = 5 * 60 * 1000;
|
|
14
10
|
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Certificate } from '../certificate.ts';
|
|
2
|
+
import type { Principal } from '#principal';
|
|
3
|
+
import type { RequestStatusResponseStatus } from '../agent/http/index.ts';
|
|
4
|
+
import type { RequestId } from '../request_id.ts';
|
|
5
|
+
|
|
6
|
+
export type PollStrategy = (
|
|
7
|
+
canisterId: Principal,
|
|
8
|
+
requestId: RequestId,
|
|
9
|
+
status: RequestStatusResponseStatus,
|
|
10
|
+
) => Promise<void>;
|
|
11
|
+
|
|
12
|
+
export type Predicate<T> = (
|
|
13
|
+
canisterId: Principal,
|
|
14
|
+
requestId: RequestId,
|
|
15
|
+
status: RequestStatusResponseStatus,
|
|
16
|
+
) => Promise<T>;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The result of polling for a response, including the certificate, reply bytes, and raw certificate bytes.
|
|
20
|
+
*/
|
|
21
|
+
export interface PollForResponseResult {
|
|
22
|
+
/** The certificate for the request, which can be used to verify the reply. */
|
|
23
|
+
certificate: Certificate;
|
|
24
|
+
/** The reply bytes for the request. */
|
|
25
|
+
reply: Uint8Array;
|
|
26
|
+
/** The raw certificate bytes for the request. */
|
|
27
|
+
rawCertificate: Uint8Array;
|
|
28
|
+
}
|
package/src/agent/public_key.ts
CHANGED
package/src/agent/request_id.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { lebEncode, compare } from '#candid';
|
|
2
|
-
import { Principal } from '#principal';
|
|
2
|
+
import type { Principal } from '#principal';
|
|
3
3
|
import { HashValueErrorCode, InputError } from './errors.ts';
|
|
4
4
|
import { uint8FromBufLike } from './utils/buffer.ts';
|
|
5
5
|
import { concatBytes } from '@noble/hashes/utils';
|
|
@@ -19,16 +19,21 @@ interface ToHashable {
|
|
|
19
19
|
export function hashValue(value: unknown): Uint8Array {
|
|
20
20
|
if (typeof value === 'string') {
|
|
21
21
|
return hashString(value);
|
|
22
|
-
}
|
|
22
|
+
}
|
|
23
|
+
if (typeof value === 'number') {
|
|
23
24
|
return sha256(lebEncode(value));
|
|
24
|
-
}
|
|
25
|
+
}
|
|
26
|
+
if (value instanceof Uint8Array || ArrayBuffer.isView(value)) {
|
|
25
27
|
return sha256(uint8FromBufLike(value));
|
|
26
|
-
}
|
|
28
|
+
}
|
|
29
|
+
if (Array.isArray(value)) {
|
|
27
30
|
const vals = value.map(hashValue);
|
|
28
31
|
return sha256(concatBytes(...vals));
|
|
29
|
-
}
|
|
32
|
+
}
|
|
33
|
+
if (value && typeof value === 'object' && (value as Principal)._isPrincipal) {
|
|
30
34
|
return sha256((value as Principal).toUint8Array());
|
|
31
|
-
}
|
|
35
|
+
}
|
|
36
|
+
if (
|
|
32
37
|
typeof value === 'object' &&
|
|
33
38
|
value !== null &&
|
|
34
39
|
typeof (value as ToHashable).toHash === 'function'
|
|
@@ -38,9 +43,11 @@ export function hashValue(value: unknown): Uint8Array {
|
|
|
38
43
|
// the flow to be synchronous to ensure Safari touch id works.
|
|
39
44
|
// } else if (value instanceof Promise) {
|
|
40
45
|
// return value.then(x => hashValue(x));
|
|
41
|
-
}
|
|
46
|
+
}
|
|
47
|
+
if (typeof value === 'object') {
|
|
42
48
|
return hashOfMap(value as Record<string, unknown>);
|
|
43
|
-
}
|
|
49
|
+
}
|
|
50
|
+
if (typeof value === 'bigint') {
|
|
44
51
|
// Do this check much later than the other bigint check because this one is much less
|
|
45
52
|
// type-safe.
|
|
46
53
|
// So we want to try all the high-assurance type guards before this 'probable' one.
|