@icp-sdk/core 5.4.0 → 6.0.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 +7 -3
- package/lib/cjs/agent/actor.d.ts.map +1 -1
- package/lib/cjs/agent/actor.js +18 -5
- package/lib/cjs/agent/actor.js.map +1 -1
- package/lib/cjs/agent/agent/api.d.ts +19 -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/index.d.ts +8 -11
- package/lib/cjs/agent/agent/http/index.d.ts.map +1 -1
- package/lib/cjs/agent/agent/http/index.js +190 -166
- package/lib/cjs/agent/agent/http/index.js.map +1 -1
- package/lib/cjs/agent/auth.d.ts +6 -5
- package/lib/cjs/agent/auth.d.ts.map +1 -1
- package/lib/cjs/agent/auth.js +3 -3
- package/lib/cjs/agent/auth.js.map +1 -1
- package/lib/cjs/agent/canisterStatus/index.d.ts.map +1 -1
- package/lib/cjs/agent/canisterStatus/index.js +10 -10
- package/lib/cjs/agent/canisterStatus/index.js.map +1 -1
- package/lib/cjs/agent/cbor.d.ts +2 -1
- package/lib/cjs/agent/cbor.d.ts.map +1 -1
- package/lib/cjs/agent/cbor.js +4 -1
- package/lib/cjs/agent/cbor.js.map +1 -1
- package/lib/cjs/agent/certificate.d.ts +5 -4
- package/lib/cjs/agent/certificate.d.ts.map +1 -1
- package/lib/cjs/agent/certificate.js +14 -18
- package/lib/cjs/agent/certificate.js.map +1 -1
- package/lib/cjs/agent/der.d.ts +3 -2
- package/lib/cjs/agent/der.d.ts.map +1 -1
- package/lib/cjs/agent/der.js.map +1 -1
- package/lib/cjs/agent/errors.d.ts +7 -1
- package/lib/cjs/agent/errors.d.ts.map +1 -1
- package/lib/cjs/agent/errors.js +34 -16
- package/lib/cjs/agent/errors.js.map +1 -1
- package/lib/cjs/agent/polling/index.d.ts +3 -4
- package/lib/cjs/agent/polling/index.d.ts.map +1 -1
- package/lib/cjs/agent/polling/index.js +17 -10
- package/lib/cjs/agent/polling/index.js.map +1 -1
- package/lib/cjs/agent/polling/strategy.d.ts.map +1 -1
- package/lib/cjs/agent/polling/strategy.js +6 -6
- package/lib/cjs/agent/polling/strategy.js.map +1 -1
- package/lib/cjs/agent/polling/types.d.ts +3 -4
- package/lib/cjs/agent/polling/types.d.ts.map +1 -1
- package/lib/cjs/agent/public_key.d.ts +3 -2
- package/lib/cjs/agent/public_key.d.ts.map +1 -1
- package/lib/cjs/agent/public_key.js +2 -2
- package/lib/cjs/agent/public_key.js.map +1 -1
- package/lib/cjs/agent/request_id.js +10 -10
- package/lib/cjs/agent/request_id.js.map +1 -1
- package/lib/cjs/agent/subnetStatus/index.js +7 -7
- package/lib/cjs/agent/subnetStatus/index.js.map +1 -1
- package/lib/cjs/agent/utils/bls.d.ts.map +1 -1
- package/lib/cjs/agent/utils/bls.js +7 -6
- package/lib/cjs/agent/utils/bls.js.map +1 -1
- package/lib/cjs/agent/utils/readState.d.ts +2 -2
- package/lib/cjs/agent/utils/readState.d.ts.map +1 -1
- package/lib/cjs/agent/utils/readState.js +4 -4
- package/lib/cjs/agent/utils/readState.js.map +1 -1
- package/lib/cjs/agent/utils/target.d.ts +15 -0
- package/lib/cjs/agent/utils/target.d.ts.map +1 -0
- package/lib/cjs/agent/utils/target.js +27 -0
- package/lib/cjs/agent/utils/target.js.map +1 -0
- package/lib/cjs/candid/utils/buffer.d.ts +2 -1
- package/lib/cjs/candid/utils/buffer.d.ts.map +1 -1
- package/lib/cjs/candid/utils/buffer.js +5 -2
- package/lib/cjs/candid/utils/buffer.js.map +1 -1
- package/lib/cjs/identity/identity/delegation.d.ts +10 -3
- package/lib/cjs/identity/identity/delegation.d.ts.map +1 -1
- package/lib/cjs/identity/identity/delegation.js +25 -12
- 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 +3 -2
- package/lib/cjs/identity/identity/ecdsa.js.map +1 -1
- package/lib/cjs/identity/identity/ed25519.d.ts +3 -2
- package/lib/cjs/identity/identity/ed25519.d.ts.map +1 -1
- package/lib/cjs/identity/identity/ed25519.js +18 -15
- package/lib/cjs/identity/identity/ed25519.js.map +1 -1
- package/lib/cjs/identity/identity/webauthn.d.ts +4 -3
- package/lib/cjs/identity/identity/webauthn.d.ts.map +1 -1
- package/lib/cjs/identity/identity/webauthn.js +12 -11
- package/lib/cjs/identity/identity/webauthn.js.map +1 -1
- package/lib/cjs/identity/secp256k1/der.d.ts +2 -1
- package/lib/cjs/identity/secp256k1/der.d.ts.map +1 -1
- package/lib/cjs/identity/secp256k1/der.js.map +1 -1
- package/lib/cjs/identity/secp256k1/pem.d.ts +4 -3
- package/lib/cjs/identity/secp256k1/pem.d.ts.map +1 -1
- package/lib/cjs/identity/secp256k1/pem.js +2 -2
- package/lib/cjs/identity/secp256k1/pem.js.map +1 -1
- package/lib/cjs/identity/secp256k1/secp256k1.d.ts +5 -4
- package/lib/cjs/identity/secp256k1/secp256k1.d.ts.map +1 -1
- package/lib/cjs/identity/secp256k1/secp256k1.js +17 -20
- package/lib/cjs/identity/secp256k1/secp256k1.js.map +1 -1
- package/lib/cjs/principal/principal.js +5 -5
- package/lib/cjs/principal/principal.js.map +1 -1
- package/lib/esm/agent/actor.d.ts +7 -3
- package/lib/esm/agent/actor.d.ts.map +1 -1
- package/lib/esm/agent/actor.js +18 -5
- package/lib/esm/agent/actor.js.map +1 -1
- package/lib/esm/agent/agent/api.d.ts +19 -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/index.d.ts +8 -11
- package/lib/esm/agent/agent/http/index.d.ts.map +1 -1
- package/lib/esm/agent/agent/http/index.js +183 -159
- package/lib/esm/agent/agent/http/index.js.map +1 -1
- package/lib/esm/agent/auth.d.ts +6 -5
- package/lib/esm/agent/auth.d.ts.map +1 -1
- package/lib/esm/agent/auth.js +1 -1
- package/lib/esm/agent/auth.js.map +1 -1
- package/lib/esm/agent/canister-env/index.js +1 -1
- package/lib/esm/agent/canister-env/index.js.map +1 -1
- package/lib/esm/agent/canisterStatus/index.d.ts.map +1 -1
- package/lib/esm/agent/canisterStatus/index.js +2 -2
- package/lib/esm/agent/canisterStatus/index.js.map +1 -1
- package/lib/esm/agent/cbor.d.ts +2 -1
- package/lib/esm/agent/cbor.d.ts.map +1 -1
- package/lib/esm/agent/cbor.js +4 -1
- package/lib/esm/agent/cbor.js.map +1 -1
- package/lib/esm/agent/certificate.d.ts +5 -4
- package/lib/esm/agent/certificate.d.ts.map +1 -1
- package/lib/esm/agent/certificate.js +5 -9
- package/lib/esm/agent/certificate.js.map +1 -1
- package/lib/esm/agent/der.d.ts +3 -2
- package/lib/esm/agent/der.d.ts.map +1 -1
- package/lib/esm/agent/der.js.map +1 -1
- package/lib/esm/agent/errors.d.ts +7 -1
- package/lib/esm/agent/errors.d.ts.map +1 -1
- package/lib/esm/agent/errors.js +18 -1
- package/lib/esm/agent/errors.js.map +1 -1
- package/lib/esm/agent/polling/index.d.ts +3 -4
- package/lib/esm/agent/polling/index.d.ts.map +1 -1
- package/lib/esm/agent/polling/index.js +15 -8
- package/lib/esm/agent/polling/index.js.map +1 -1
- package/lib/esm/agent/polling/strategy.d.ts.map +1 -1
- package/lib/esm/agent/polling/strategy.js +6 -6
- package/lib/esm/agent/polling/strategy.js.map +1 -1
- package/lib/esm/agent/polling/types.d.ts +3 -4
- package/lib/esm/agent/polling/types.d.ts.map +1 -1
- package/lib/esm/agent/public_key.d.ts +3 -2
- package/lib/esm/agent/public_key.d.ts.map +1 -1
- package/lib/esm/agent/public_key.js +2 -2
- package/lib/esm/agent/public_key.js.map +1 -1
- package/lib/esm/agent/request_id.js +2 -2
- package/lib/esm/agent/request_id.js.map +1 -1
- package/lib/esm/agent/subnetStatus/index.js +1 -1
- package/lib/esm/agent/subnetStatus/index.js.map +1 -1
- package/lib/esm/agent/utils/bls.d.ts.map +1 -1
- package/lib/esm/agent/utils/bls.js +7 -6
- package/lib/esm/agent/utils/bls.js.map +1 -1
- package/lib/esm/agent/utils/readState.d.ts +2 -2
- package/lib/esm/agent/utils/readState.d.ts.map +1 -1
- package/lib/esm/agent/utils/readState.js +1 -1
- package/lib/esm/agent/utils/readState.js.map +1 -1
- package/lib/esm/agent/utils/target.d.ts +15 -0
- package/lib/esm/agent/utils/target.d.ts.map +1 -0
- package/lib/esm/agent/utils/target.js +23 -0
- package/lib/esm/agent/utils/target.js.map +1 -0
- package/lib/esm/candid/utils/buffer.d.ts +2 -1
- package/lib/esm/candid/utils/buffer.d.ts.map +1 -1
- package/lib/esm/candid/utils/buffer.js +5 -2
- package/lib/esm/candid/utils/buffer.js.map +1 -1
- package/lib/esm/identity/identity/delegation.d.ts +10 -3
- package/lib/esm/identity/identity/delegation.d.ts.map +1 -1
- package/lib/esm/identity/identity/delegation.js +22 -9
- 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 +3 -2
- package/lib/esm/identity/identity/ecdsa.js.map +1 -1
- package/lib/esm/identity/identity/ed25519.d.ts +3 -2
- package/lib/esm/identity/identity/ed25519.d.ts.map +1 -1
- package/lib/esm/identity/identity/ed25519.js +10 -7
- package/lib/esm/identity/identity/ed25519.js.map +1 -1
- package/lib/esm/identity/identity/webauthn.d.ts +4 -3
- package/lib/esm/identity/identity/webauthn.d.ts.map +1 -1
- package/lib/esm/identity/identity/webauthn.js +8 -7
- package/lib/esm/identity/identity/webauthn.js.map +1 -1
- package/lib/esm/identity/secp256k1/der.d.ts +2 -1
- package/lib/esm/identity/secp256k1/der.d.ts.map +1 -1
- package/lib/esm/identity/secp256k1/der.js.map +1 -1
- package/lib/esm/identity/secp256k1/pem.d.ts +4 -3
- package/lib/esm/identity/secp256k1/pem.d.ts.map +1 -1
- package/lib/esm/identity/secp256k1/pem.js +2 -2
- package/lib/esm/identity/secp256k1/pem.js.map +1 -1
- package/lib/esm/identity/secp256k1/secp256k1.d.ts +5 -4
- package/lib/esm/identity/secp256k1/secp256k1.d.ts.map +1 -1
- package/lib/esm/identity/secp256k1/secp256k1.js +10 -13
- package/lib/esm/identity/secp256k1/secp256k1.js.map +1 -1
- package/lib/esm/principal/principal.js +2 -2
- package/lib/esm/principal/principal.js.map +1 -1
- package/package.json +20 -10
- package/src/agent/actor.ts +0 -524
- package/src/agent/agent/api.ts +0 -310
- package/src/agent/agent/http/expiry.ts +0 -107
- package/src/agent/agent/http/index.ts +0 -1724
- package/src/agent/agent/http/transforms.ts +0 -54
- package/src/agent/agent/http/types.ts +0 -145
- package/src/agent/agent/index.ts +0 -4
- package/src/agent/auth.ts +0 -147
- package/src/agent/canister-env/index.ts +0 -192
- package/src/agent/canisterStatus/index.ts +0 -260
- package/src/agent/cbor.ts +0 -63
- package/src/agent/certificate.ts +0 -1058
- package/src/agent/constants.ts +0 -24
- package/src/agent/der.ts +0 -191
- package/src/agent/errors.ts +0 -962
- package/src/agent/fetch_candid.ts +0 -37
- package/src/agent/index.ts +0 -130
- package/src/agent/observable.ts +0 -49
- package/src/agent/polling/backoff.ts +0 -129
- package/src/agent/polling/index.ts +0 -238
- package/src/agent/polling/strategy.ts +0 -140
- package/src/agent/polling/types.ts +0 -28
- package/src/agent/public_key.ts +0 -65
- package/src/agent/request_id.ts +0 -99
- package/src/agent/subnetStatus/index.ts +0 -263
- package/src/agent/utils/bls.ts +0 -18
- package/src/agent/utils/buffer.ts +0 -64
- package/src/agent/utils/certificateReject.ts +0 -25
- package/src/agent/utils/createExpirableStore.ts +0 -31
- package/src/agent/utils/expirableStore.ts +0 -47
- package/src/agent/utils/inMemoryExpirableStore.ts +0 -49
- package/src/agent/utils/indexedDBExpirableStore.ts +0 -191
- package/src/agent/utils/leb.ts +0 -14
- package/src/agent/utils/random.ts +0 -30
- package/src/agent/utils/readState.ts +0 -180
- package/src/candid/candid-core.ts +0 -274
- package/src/candid/candid-ui.ts +0 -281
- package/src/candid/idl.ts +0 -2654
- package/src/candid/index.ts +0 -35
- package/src/candid/types.ts +0 -7
- package/src/candid/utils/bigint-math.ts +0 -26
- package/src/candid/utils/buffer.ts +0 -221
- package/src/candid/utils/hash.ts +0 -31
- package/src/candid/utils/leb128.ts +0 -233
- package/src/identity/identity/attributes.ts +0 -91
- package/src/identity/identity/delegation.ts +0 -411
- package/src/identity/identity/ecdsa.ts +0 -162
- package/src/identity/identity/ed25519.ts +0 -246
- package/src/identity/identity/partial.ts +0 -60
- package/src/identity/identity/webauthn.ts +0 -265
- package/src/identity/index.ts +0 -44
- package/src/identity/secp256k1/der.ts +0 -177
- package/src/identity/secp256k1/index.ts +0 -52
- package/src/identity/secp256k1/pem.ts +0 -39
- package/src/identity/secp256k1/secp256k1.ts +0 -276
- package/src/index.ts +0 -3
- package/src/principal/index.ts +0 -19
- package/src/principal/principal.ts +0 -181
- package/src/principal/utils/base32.ts +0 -101
- package/src/principal/utils/getCrc.ts +0 -52
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
import { Principal } from '#principal';
|
|
2
|
-
import {
|
|
3
|
-
CertificateVerificationErrorCode,
|
|
4
|
-
MissingRootKeyErrorCode,
|
|
5
|
-
ExternalError,
|
|
6
|
-
AgentError,
|
|
7
|
-
UnknownError,
|
|
8
|
-
UnexpectedErrorCode,
|
|
9
|
-
InputError,
|
|
10
|
-
CertificateTimeErrorCode,
|
|
11
|
-
} from '../errors.ts';
|
|
12
|
-
import type { HttpAgent } from '../agent/http/index.ts';
|
|
13
|
-
import { type Cert, Certificate, lookupResultToBuffer } from '../certificate.ts';
|
|
14
|
-
import * as cbor from '../cbor.ts';
|
|
15
|
-
import { decodeTime } from '../utils/leb.ts';
|
|
16
|
-
import { utf8ToBytes, bytesToHex } from '@noble/hashes/utils';
|
|
17
|
-
import type { CustomPath } from '../utils/readState.ts';
|
|
18
|
-
import {
|
|
19
|
-
type BaseSubnetStatus,
|
|
20
|
-
type BaseStatus,
|
|
21
|
-
decodeValue,
|
|
22
|
-
decodeControllers,
|
|
23
|
-
encodeMetadataPath,
|
|
24
|
-
isCustomPath,
|
|
25
|
-
lookupNodeKeysFromCertificate,
|
|
26
|
-
IC_ROOT_SUBNET_ID,
|
|
27
|
-
} from '../utils/readState.ts';
|
|
28
|
-
|
|
29
|
-
// Re-export shared types for backwards compatibility
|
|
30
|
-
export { type DecodeStrategy, CustomPath } from '../utils/readState.ts';
|
|
31
|
-
|
|
32
|
-
export type SubnetStatus = BaseSubnetStatus;
|
|
33
|
-
export type Status = BaseStatus | SubnetStatus;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Pre-configured fields for canister status paths
|
|
37
|
-
*/
|
|
38
|
-
export type Path = 'time' | 'controllers' | 'subnet' | 'module_hash' | 'candid' | CustomPath;
|
|
39
|
-
|
|
40
|
-
export type StatusMap = Map<Path | string, Status>;
|
|
41
|
-
|
|
42
|
-
export interface CanisterStatusOptions {
|
|
43
|
-
/**
|
|
44
|
-
* The effective canister ID to use in the underlying {@link HttpAgent.readState} call.
|
|
45
|
-
*/
|
|
46
|
-
canisterId: Principal;
|
|
47
|
-
/**
|
|
48
|
-
* The agent to use to make the canister request. Must be authenticated.
|
|
49
|
-
*/
|
|
50
|
-
agent: HttpAgent;
|
|
51
|
-
/**
|
|
52
|
-
* The paths to request.
|
|
53
|
-
* @default []
|
|
54
|
-
*/
|
|
55
|
-
paths?: Path[] | Set<Path>;
|
|
56
|
-
/**
|
|
57
|
-
* Whether to disable the certificate freshness checks.
|
|
58
|
-
* @default false
|
|
59
|
-
*/
|
|
60
|
-
disableCertificateTimeVerification?: boolean;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Requests information from a canister's `read_state` endpoint.
|
|
65
|
-
* Can be used to request information about the canister's controllers, time, module hash, candid interface, and more.
|
|
66
|
-
*
|
|
67
|
-
* > [!WARNING]
|
|
68
|
-
* > Requesting the `subnet` path from the canister status might be deprecated in the future.
|
|
69
|
-
* > Use {@link https://js.icp.build/core/latest/libs/agent/api/namespaces/subnetstatus/functions/request | SubnetStatus.request} to fetch subnet information instead.
|
|
70
|
-
* @param {CanisterStatusOptions} options The configuration for the canister status request.
|
|
71
|
-
* @see {@link CanisterStatusOptions} for detailed options.
|
|
72
|
-
* @returns {Promise<StatusMap>} A map populated with data from the requested paths. Each path is a key in the map, and the value is the data obtained from the certificate for that path.
|
|
73
|
-
* @example
|
|
74
|
-
* const status = await canisterStatus({
|
|
75
|
-
* paths: ['controllers', 'candid'],
|
|
76
|
-
* ...options
|
|
77
|
-
* });
|
|
78
|
-
*
|
|
79
|
-
* const controllers = status.get('controllers');
|
|
80
|
-
*/
|
|
81
|
-
export const request = async (options: CanisterStatusOptions): Promise<StatusMap> => {
|
|
82
|
-
const { agent, paths, disableCertificateTimeVerification = false } = options;
|
|
83
|
-
const canisterId = Principal.from(options.canisterId);
|
|
84
|
-
|
|
85
|
-
const uniquePaths = [...new Set(paths)];
|
|
86
|
-
const status = new Map<string | Path, Status>();
|
|
87
|
-
|
|
88
|
-
const promises = uniquePaths.map((path, index) => {
|
|
89
|
-
const encodedPath = encodePath(path, canisterId);
|
|
90
|
-
|
|
91
|
-
return (async () => {
|
|
92
|
-
try {
|
|
93
|
-
if (agent.rootKey === null) {
|
|
94
|
-
throw ExternalError.fromCode(new MissingRootKeyErrorCode());
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const rootKey = agent.rootKey;
|
|
98
|
-
|
|
99
|
-
const response = await agent.readState(canisterId, {
|
|
100
|
-
paths: [encodedPath],
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
const certificate = await Certificate.create({
|
|
104
|
-
certificate: response.certificate,
|
|
105
|
-
rootKey,
|
|
106
|
-
principal: { canisterId },
|
|
107
|
-
disableTimeVerification: disableCertificateTimeVerification,
|
|
108
|
-
agent,
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
const lookup = (cert: Certificate, path: Path) => {
|
|
112
|
-
if (path === 'subnet') {
|
|
113
|
-
const data = fetchNodeKeys(response.certificate, canisterId, rootKey);
|
|
114
|
-
return {
|
|
115
|
-
path,
|
|
116
|
-
data,
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
return {
|
|
120
|
-
path,
|
|
121
|
-
data: lookupResultToBuffer(cert.lookup_path(encodedPath)),
|
|
122
|
-
};
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
// must pass in the rootKey if we have no delegation
|
|
126
|
-
const { path, data } = lookup(certificate, uniquePaths[index]);
|
|
127
|
-
if (!data) {
|
|
128
|
-
// Typically, the cert lookup will throw
|
|
129
|
-
if (typeof path === 'string') {
|
|
130
|
-
status.set(path, null);
|
|
131
|
-
} else {
|
|
132
|
-
status.set(path.key, null);
|
|
133
|
-
}
|
|
134
|
-
} else {
|
|
135
|
-
switch (path) {
|
|
136
|
-
case 'time': {
|
|
137
|
-
status.set(path, decodeTime(data));
|
|
138
|
-
break;
|
|
139
|
-
}
|
|
140
|
-
case 'controllers': {
|
|
141
|
-
status.set(path, decodeControllers(data));
|
|
142
|
-
break;
|
|
143
|
-
}
|
|
144
|
-
case 'module_hash': {
|
|
145
|
-
status.set(path, bytesToHex(data));
|
|
146
|
-
break;
|
|
147
|
-
}
|
|
148
|
-
case 'subnet': {
|
|
149
|
-
status.set(path, data);
|
|
150
|
-
break;
|
|
151
|
-
}
|
|
152
|
-
case 'candid': {
|
|
153
|
-
status.set(path, new TextDecoder().decode(data));
|
|
154
|
-
break;
|
|
155
|
-
}
|
|
156
|
-
default: {
|
|
157
|
-
// Check for CustomPath signature
|
|
158
|
-
if (isCustomPath(path)) {
|
|
159
|
-
status.set(path.key, decodeValue(data, path.decodeStrategy));
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
} catch (error) {
|
|
165
|
-
// Throw on certificate errors
|
|
166
|
-
if (
|
|
167
|
-
error instanceof AgentError &&
|
|
168
|
-
(error.hasCode(CertificateVerificationErrorCode) ||
|
|
169
|
-
error.hasCode(CertificateTimeErrorCode))
|
|
170
|
-
) {
|
|
171
|
-
throw error;
|
|
172
|
-
}
|
|
173
|
-
if (isCustomPath(path)) {
|
|
174
|
-
status.set(path.key, null);
|
|
175
|
-
} else {
|
|
176
|
-
status.set(path, null);
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
})();
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
// Fetch all values separately, as each option can fail
|
|
183
|
-
await Promise.all(promises);
|
|
184
|
-
|
|
185
|
-
return status;
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Lookup node keys from a certificate for a given canister.
|
|
190
|
-
* The certificate is assumed to be already verified, including whether the canister is in range of the subnet.
|
|
191
|
-
* @param certificate the certificate to lookup node keys from
|
|
192
|
-
* @param canisterId the canister ID to lookup node keys for
|
|
193
|
-
* @param root_key the root key to use to lookup node keys
|
|
194
|
-
* @returns a map of node IDs to public keys
|
|
195
|
-
*/
|
|
196
|
-
export const fetchNodeKeys = (
|
|
197
|
-
certificate: Uint8Array,
|
|
198
|
-
canisterId: Principal,
|
|
199
|
-
root_key?: Uint8Array,
|
|
200
|
-
): BaseSubnetStatus => {
|
|
201
|
-
if (!canisterId._isPrincipal) {
|
|
202
|
-
throw InputError.fromCode(new UnexpectedErrorCode('Invalid canisterId'));
|
|
203
|
-
}
|
|
204
|
-
const cert = cbor.decode<Cert>(certificate);
|
|
205
|
-
const { delegation } = cert;
|
|
206
|
-
let subnetId: Principal;
|
|
207
|
-
if (delegation && delegation.subnet_id) {
|
|
208
|
-
subnetId = Principal.fromUint8Array(new Uint8Array(delegation.subnet_id));
|
|
209
|
-
} else if (!delegation && typeof root_key !== 'undefined') {
|
|
210
|
-
// On local replica, with System type subnet, there is no delegation
|
|
211
|
-
subnetId = Principal.selfAuthenticating(new Uint8Array(root_key));
|
|
212
|
-
} else {
|
|
213
|
-
// otherwise use default NNS subnet id
|
|
214
|
-
subnetId = IC_ROOT_SUBNET_ID;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
const nodeKeys = lookupNodeKeysFromCertificate(cert, subnetId);
|
|
218
|
-
|
|
219
|
-
return {
|
|
220
|
-
subnetId: subnetId.toText(),
|
|
221
|
-
nodeKeys,
|
|
222
|
-
};
|
|
223
|
-
};
|
|
224
|
-
|
|
225
|
-
export const encodePath = (path: Path, canisterId: Principal): Uint8Array[] => {
|
|
226
|
-
const canisterUint8Array = canisterId.toUint8Array();
|
|
227
|
-
switch (path) {
|
|
228
|
-
case 'time':
|
|
229
|
-
return [utf8ToBytes('time')];
|
|
230
|
-
case 'controllers':
|
|
231
|
-
return [utf8ToBytes('canister'), canisterUint8Array, utf8ToBytes('controllers')];
|
|
232
|
-
case 'module_hash':
|
|
233
|
-
return [utf8ToBytes('canister'), canisterUint8Array, utf8ToBytes('module_hash')];
|
|
234
|
-
case 'subnet':
|
|
235
|
-
return [utf8ToBytes('subnet')];
|
|
236
|
-
case 'candid':
|
|
237
|
-
return [
|
|
238
|
-
utf8ToBytes('canister'),
|
|
239
|
-
canisterUint8Array,
|
|
240
|
-
utf8ToBytes('metadata'),
|
|
241
|
-
utf8ToBytes('candid:service'),
|
|
242
|
-
];
|
|
243
|
-
default: {
|
|
244
|
-
// Check for CustomPath signature
|
|
245
|
-
if (isCustomPath(path)) {
|
|
246
|
-
// For simplified metadata queries
|
|
247
|
-
if (typeof path['path'] === 'string' || path['path'] instanceof Uint8Array) {
|
|
248
|
-
return encodeMetadataPath(path.path, canisterUint8Array);
|
|
249
|
-
}
|
|
250
|
-
// For non-metadata, return the provided custom path
|
|
251
|
-
return path['path'];
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
throw UnknownError.fromCode(
|
|
256
|
-
new UnexpectedErrorCode(
|
|
257
|
-
`Error while encoding your path for canister status. Please ensure that your path ${path} was formatted correctly.`,
|
|
258
|
-
),
|
|
259
|
-
);
|
|
260
|
-
};
|
package/src/agent/cbor.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { Principal } from '#principal';
|
|
2
|
-
import * as cbor from '@dfinity/cbor';
|
|
3
|
-
import { CborDecodeErrorCode, CborEncodeErrorCode, InputError } from './errors.ts';
|
|
4
|
-
import { Expiry } from './agent/http/expiry.ts';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Used to extend classes that need to provide a custom value for the CBOR encoding process.
|
|
8
|
-
*/
|
|
9
|
-
export abstract class ToCborValue {
|
|
10
|
-
/**
|
|
11
|
-
* Returns a value that can be encoded with CBOR. Typically called in the replacer function of the {@link encode} function.
|
|
12
|
-
*/
|
|
13
|
-
public abstract toCborValue(): cbor.CborValue;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function hasCborValueMethod(value: unknown): value is ToCborValue {
|
|
17
|
-
return typeof value === 'object' && value !== null && 'toCborValue' in value;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Encode a JavaScript value into CBOR. If the value is an instance of {@link ToCborValue},
|
|
22
|
-
* the {@link ToCborValue.toCborValue} method will be called to get the value to encode.
|
|
23
|
-
* @param value The value to encode
|
|
24
|
-
*/
|
|
25
|
-
export function encode(value: unknown): Uint8Array {
|
|
26
|
-
try {
|
|
27
|
-
return cbor.encodeWithSelfDescribedTag(value, value => {
|
|
28
|
-
if (Principal.isPrincipal(value)) {
|
|
29
|
-
return value.toUint8Array();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (Expiry.isExpiry(value)) {
|
|
33
|
-
return value.toBigInt();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (hasCborValueMethod(value)) {
|
|
37
|
-
return value.toCborValue();
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return value;
|
|
41
|
-
});
|
|
42
|
-
} catch (error) {
|
|
43
|
-
throw InputError.fromCode(new CborEncodeErrorCode(error, value));
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Decode a CBOR encoded value into a JavaScript value.
|
|
49
|
-
* @param input The CBOR encoded value
|
|
50
|
-
*/
|
|
51
|
-
export function decode<T>(input: Uint8Array): T {
|
|
52
|
-
try {
|
|
53
|
-
return cbor.decode(input) as T;
|
|
54
|
-
} catch (error) {
|
|
55
|
-
throw InputError.fromCode(new CborDecodeErrorCode(error, input));
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// Not strictly necessary, we're just keeping it for backwards compatibility.
|
|
60
|
-
export const Cbor = {
|
|
61
|
-
encode,
|
|
62
|
-
decode,
|
|
63
|
-
};
|