@icp-sdk/core 6.0.0 → 6.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/agent/api.d.ts +52 -4
- package/lib/cjs/agent/agent/api.d.ts.map +1 -1
- package/lib/cjs/agent/agent/api.js +6 -1
- package/lib/cjs/agent/agent/api.js.map +1 -1
- package/lib/cjs/agent/agent/http/index.d.ts +2 -2
- package/lib/cjs/agent/agent/http/index.d.ts.map +1 -1
- package/lib/cjs/agent/agent/http/index.js +41 -17
- package/lib/cjs/agent/agent/http/index.js.map +1 -1
- package/lib/cjs/agent/canisterStatus/index.d.ts +2 -3
- package/lib/cjs/agent/canisterStatus/index.d.ts.map +1 -1
- package/lib/cjs/agent/canisterStatus/index.js +63 -120
- package/lib/cjs/agent/canisterStatus/index.js.map +1 -1
- package/lib/cjs/agent/certificate.d.ts +1 -1
- package/lib/cjs/agent/certificate.d.ts.map +1 -1
- package/lib/cjs/agent/certificate.js.map +1 -1
- package/lib/cjs/agent/polling/index.d.ts +4 -3
- package/lib/cjs/agent/polling/index.d.ts.map +1 -1
- package/lib/cjs/agent/polling/index.js +5 -13
- package/lib/cjs/agent/polling/index.js.map +1 -1
- package/lib/cjs/agent/subnetStatus/index.d.ts +3 -2
- package/lib/cjs/agent/subnetStatus/index.d.ts.map +1 -1
- package/lib/cjs/agent/subnetStatus/index.js +59 -82
- package/lib/cjs/agent/subnetStatus/index.js.map +1 -1
- package/lib/cjs/agent/utils/readState.d.ts +102 -13
- package/lib/cjs/agent/utils/readState.d.ts.map +1 -1
- package/lib/cjs/agent/utils/readState.js +104 -15
- package/lib/cjs/agent/utils/readState.js.map +1 -1
- package/lib/esm/agent/agent/api.d.ts +52 -4
- package/lib/esm/agent/agent/api.d.ts.map +1 -1
- package/lib/esm/agent/agent/api.js +1 -0
- package/lib/esm/agent/agent/api.js.map +1 -1
- package/lib/esm/agent/agent/http/index.d.ts +2 -2
- package/lib/esm/agent/agent/http/index.d.ts.map +1 -1
- package/lib/esm/agent/agent/http/index.js +42 -18
- package/lib/esm/agent/agent/http/index.js.map +1 -1
- package/lib/esm/agent/canisterStatus/index.d.ts +2 -3
- package/lib/esm/agent/canisterStatus/index.d.ts.map +1 -1
- package/lib/esm/agent/canisterStatus/index.js +65 -121
- package/lib/esm/agent/canisterStatus/index.js.map +1 -1
- package/lib/esm/agent/certificate.d.ts +1 -1
- package/lib/esm/agent/certificate.d.ts.map +1 -1
- package/lib/esm/agent/certificate.js.map +1 -1
- package/lib/esm/agent/polling/index.d.ts +4 -3
- package/lib/esm/agent/polling/index.d.ts.map +1 -1
- package/lib/esm/agent/polling/index.js +7 -15
- package/lib/esm/agent/polling/index.js.map +1 -1
- package/lib/esm/agent/subnetStatus/index.d.ts +3 -2
- package/lib/esm/agent/subnetStatus/index.d.ts.map +1 -1
- package/lib/esm/agent/subnetStatus/index.js +62 -85
- package/lib/esm/agent/subnetStatus/index.js.map +1 -1
- package/lib/esm/agent/utils/readState.d.ts +102 -13
- package/lib/esm/agent/utils/readState.d.ts.map +1 -1
- package/lib/esm/agent/utils/readState.js +102 -15
- package/lib/esm/agent/utils/readState.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,18 +1,47 @@
|
|
|
1
1
|
import { Principal } from '../../principal/index.js';
|
|
2
|
-
import { CertificateVerificationErrorCode,
|
|
3
|
-
import {
|
|
2
|
+
import { CertificateVerificationErrorCode, AgentError, UnknownError, UnexpectedErrorCode, CertificateTimeErrorCode, ProtocolError, LookupErrorCode, MissingRootKeyErrorCode, } from "../errors.js";
|
|
3
|
+
import { lookup_path, LookupPathStatus } from "../certificate.js";
|
|
4
4
|
import * as cbor from "../cbor.js";
|
|
5
|
-
import { decodeTime } from "../utils/leb.js";
|
|
6
5
|
import { utf8ToBytes } from '@noble/hashes/utils.js';
|
|
7
|
-
import { decodeValue, isCustomPath, lookupNodeKeysFromCertificate, } from "../utils/readState.js";
|
|
6
|
+
import { KnownPath, StatePaths, decodeValue, isCustomPath, lookupNodeKeysFromCertificate, } from "../utils/readState.js";
|
|
8
7
|
// Re-export shared types and functions
|
|
9
8
|
export { CustomPath, IC_ROOT_SUBNET_ID } from "../utils/readState.js";
|
|
9
|
+
/**
|
|
10
|
+
* Build the {@link KnownPath} for a named (non-`nodeKeys`) subnet status path. `nodeKeys` is handled
|
|
11
|
+
* separately, as its value is derived from the raw certificate.
|
|
12
|
+
* @param path the named subnet status path
|
|
13
|
+
* @param subnetId the subnet the request targets
|
|
14
|
+
*/
|
|
15
|
+
const namedToKnown = (path, subnetId) => {
|
|
16
|
+
switch (path) {
|
|
17
|
+
case 'time':
|
|
18
|
+
return StatePaths.time;
|
|
19
|
+
case 'publicKey':
|
|
20
|
+
return StatePaths.subnetPublicKey(subnetId);
|
|
21
|
+
case 'canisterRanges':
|
|
22
|
+
return StatePaths.subnetCanisterRanges(subnetId);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Translate a user-provided {@link CustomPath} into a {@link KnownPath} that {@link HttpAgent.readState}
|
|
27
|
+
* can encode and decode. A string or single-buffer path names a segment under the subnet subtree.
|
|
28
|
+
* @param custom the user-provided custom path
|
|
29
|
+
* @param subnetId the subnet to scope a simple path to
|
|
30
|
+
*/
|
|
31
|
+
const customToKnown = (custom, subnetId) => {
|
|
32
|
+
const decode = (bytes) => decodeValue(bytes, custom.decodeStrategy);
|
|
33
|
+
if (typeof custom.path === 'string' || custom.path instanceof Uint8Array) {
|
|
34
|
+
return new KnownPath(['subnet', subnetId.toUint8Array(), custom.path], decode);
|
|
35
|
+
}
|
|
36
|
+
return new KnownPath(custom.path, decode);
|
|
37
|
+
};
|
|
10
38
|
/**
|
|
11
39
|
* Requests information from a subnet's `read_state` endpoint.
|
|
12
40
|
* Can be used to request information about the subnet's time, canister ranges, public key, node keys, and metrics.
|
|
13
41
|
* @param {SubnetStatusOptions} options The configuration for the subnet status request.
|
|
14
42
|
* @see {@link SubnetStatusOptions} for detailed options.
|
|
15
43
|
* @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.
|
|
44
|
+
* @deprecated Use {@link HttpAgent.readState} directly with {@link StatePaths} instead. This function will be removed in a future release.
|
|
16
45
|
* @example
|
|
17
46
|
* const status = await subnetStatus.request({
|
|
18
47
|
* subnetId: IC_ROOT_SUBNET_ID,
|
|
@@ -26,91 +55,38 @@ export { CustomPath, IC_ROOT_SUBNET_ID } from "../utils/readState.js";
|
|
|
26
55
|
export async function request(options) {
|
|
27
56
|
const { agent, paths, disableCertificateTimeVerification = false } = options;
|
|
28
57
|
const subnetId = Principal.from(options.subnetId);
|
|
29
|
-
const uniquePaths = [...new Set(paths)];
|
|
58
|
+
const uniquePaths = [...new Set(paths ?? [])];
|
|
30
59
|
const status = new Map();
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const rootKey = agent.rootKey;
|
|
39
|
-
const response = await agent.readSubnetState(subnetId, {
|
|
40
|
-
paths: [encodedPath],
|
|
41
|
-
});
|
|
42
|
-
const certificate = await Certificate.create({
|
|
43
|
-
certificate: response.certificate,
|
|
44
|
-
rootKey,
|
|
45
|
-
principal: { subnetId },
|
|
60
|
+
const keyOf = (path) => (typeof path === 'string' ? path : path.key);
|
|
61
|
+
const promises = uniquePaths.map(async (path) => {
|
|
62
|
+
try {
|
|
63
|
+
// The nodeKeys path resolves to per-node public keys, which require parsing the raw certificate.
|
|
64
|
+
if (path === 'nodeKeys') {
|
|
65
|
+
const { verifiedCertificate } = await agent.readState({ subnetId }, {
|
|
66
|
+
paths: [[utf8ToBytes('subnet'), subnetId.toUint8Array(), utf8ToBytes('node')]],
|
|
46
67
|
disableTimeVerification: disableCertificateTimeVerification,
|
|
47
|
-
agent,
|
|
48
68
|
});
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
// For node keys, we need to parse the certificate directly
|
|
52
|
-
const data = lookupNodeKeysFromCertificate(cert.cert, subnetId);
|
|
53
|
-
return {
|
|
54
|
-
path: lookupPath,
|
|
55
|
-
data,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
return {
|
|
59
|
-
path: lookupPath,
|
|
60
|
-
data: lookupResultToBuffer(cert.lookup_path(encodedPath)),
|
|
61
|
-
};
|
|
62
|
-
};
|
|
63
|
-
const { path, data } = lookup(certificate, uniquePaths[index]);
|
|
64
|
-
if (!data) {
|
|
65
|
-
if (typeof path === 'string') {
|
|
66
|
-
status.set(path, null);
|
|
67
|
-
}
|
|
68
|
-
else {
|
|
69
|
-
status.set(path.key, null);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
switch (path) {
|
|
74
|
-
case 'time': {
|
|
75
|
-
status.set(path, decodeTime(data));
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
|
-
case 'canisterRanges': {
|
|
79
|
-
status.set(path, decodeCanisterRanges(data));
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
case 'publicKey': {
|
|
83
|
-
status.set(path, data);
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
case 'nodeKeys': {
|
|
87
|
-
status.set(path, data);
|
|
88
|
-
break;
|
|
89
|
-
}
|
|
90
|
-
default: {
|
|
91
|
-
// Check for CustomPath signature
|
|
92
|
-
if (isCustomPath(path)) {
|
|
93
|
-
status.set(path.key, decodeValue(data, path.decodeStrategy));
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
69
|
+
status.set('nodeKeys', lookupNodeKeysFromCertificate(verifiedCertificate.cert, subnetId));
|
|
70
|
+
return;
|
|
98
71
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
72
|
+
// Translate to a KnownPath and let readState encode and decode it.
|
|
73
|
+
const known = typeof path === 'string' ? namedToKnown(path, subnetId) : customToKnown(path, subnetId);
|
|
74
|
+
const { values } = await agent.readState({ subnetId }, {
|
|
75
|
+
paths: [known],
|
|
76
|
+
disableTimeVerification: disableCertificateTimeVerification,
|
|
77
|
+
});
|
|
78
|
+
status.set(keyOf(path), values.get(known));
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
// Throw on certificate errors
|
|
82
|
+
if (error instanceof AgentError &&
|
|
83
|
+
(error.hasCode(CertificateVerificationErrorCode) ||
|
|
84
|
+
error.hasCode(CertificateTimeErrorCode) ||
|
|
85
|
+
error.hasCode(MissingRootKeyErrorCode))) {
|
|
86
|
+
throw error;
|
|
112
87
|
}
|
|
113
|
-
|
|
88
|
+
status.set(keyOf(path), null);
|
|
89
|
+
}
|
|
114
90
|
});
|
|
115
91
|
// Fetch all values separately, as each option can fail
|
|
116
92
|
await Promise.all(promises);
|
|
@@ -141,6 +117,7 @@ function lookupSubnetPublicKey(certificate, subnetId) {
|
|
|
141
117
|
}
|
|
142
118
|
/**
|
|
143
119
|
* Encode a path for subnet state queries
|
|
120
|
+
* @deprecated Use {@link HttpAgent.readState} directly with {@link StatePaths} instead
|
|
144
121
|
* @param path the path to encode
|
|
145
122
|
* @param subnetId the subnet ID
|
|
146
123
|
* @returns the encoded path as an array of Uint8Arrays
|
|
@@ -151,7 +128,7 @@ export function encodePath(path, subnetId) {
|
|
|
151
128
|
case 'time':
|
|
152
129
|
return [utf8ToBytes('time')];
|
|
153
130
|
case 'canisterRanges':
|
|
154
|
-
return [utf8ToBytes('
|
|
131
|
+
return [utf8ToBytes('subnet'), subnetUint8Array, utf8ToBytes('canister_ranges')];
|
|
155
132
|
case 'publicKey':
|
|
156
133
|
return [utf8ToBytes('subnet'), subnetUint8Array, utf8ToBytes('public_key')];
|
|
157
134
|
case 'nodeKeys':
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/agent/subnetStatus/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EACL,gCAAgC,EAChC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/agent/subnetStatus/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EACL,gCAAgC,EAChC,UAAU,EACV,YAAY,EACZ,mBAAmB,EACnB,wBAAwB,EACxB,aAAa,EACb,eAAe,EACf,uBAAuB,GACxB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAkC,WAAW,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAClG,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAKL,SAAS,EACT,UAAU,EACV,WAAW,EACX,YAAY,EACZ,6BAA6B,GAE9B,MAAM,uBAAuB,CAAC;AAE/B,uCAAuC;AACvC,OAAO,EAAuB,UAAU,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAkB3F;;;;;GAKG;AACH,MAAM,YAAY,GAAG,CACnB,IAA4C,EAC5C,QAAmB,EACA,EAAE;IACrB,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,MAAM;YACT,OAAO,UAAU,CAAC,IAAI,CAAC;QACzB,KAAK,WAAW;YACd,OAAO,UAAU,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;QAC9C,KAAK,gBAAgB;YACnB,OAAO,UAAU,CAAC,oBAAoB,CAAC,QAAQ,CAAC,CAAC;IACrD,CAAC;AACH,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,aAAa,GAAG,CAAC,MAAkB,EAAE,QAAmB,EAAyB,EAAE;IACvF,MAAM,MAAM,GAAG,CAAC,KAAiB,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gBAAgB,EAAE,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC;QAC9E,KAAK,UAAU;YACb,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,gBAAgB,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;QACxE,OAAO,CAAC,CAAC,CAAC;YACR,iCAAiC;YACjC,IAAI,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;gBACvB,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,CAAC,YAAY,UAAU,EAAE,CAAC;oBAC3E,mDAAmD;oBACnD,MAAM,OAAO,GACX,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;oBAC9E,OAAO,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,gBAAgB,EAAE,OAAO,CAAC,CAAC;gBAC5D,CAAC;gBACD,wDAAwD;gBACxD,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC;YACtB,CAAC;QACH,CAAC;IACH,CAAC;IACD,MAAM,YAAY,CAAC,QAAQ,CACzB,IAAI,mBAAmB,CACrB,kFAAkF,IAAI,2BAA2B,CAClH,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Principal } from '../../principal/index.js';
|
|
2
2
|
import type { DerEncodedPublicKey } from '../auth.ts';
|
|
3
|
-
import { type Cert } from '../certificate.ts';
|
|
3
|
+
import { type Cert, type CanisterRanges } from '../certificate.ts';
|
|
4
4
|
/**
|
|
5
5
|
* The root subnet ID for IC mainnet
|
|
6
6
|
*/
|
|
@@ -29,21 +29,117 @@ export interface BaseSubnetStatus {
|
|
|
29
29
|
*/
|
|
30
30
|
export type BaseStatus = string | Uint8Array | Date | Uint8Array[] | Principal[] | bigint | null;
|
|
31
31
|
/**
|
|
32
|
-
* Decode strategy for
|
|
32
|
+
* Decode strategy for a {@link CustomPath}. `'raw'` returns the looked-up bytes unchanged.
|
|
33
33
|
*/
|
|
34
34
|
export type DecodeStrategy = 'cbor' | 'hex' | 'leb128' | 'utf-8' | 'raw';
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
36
|
+
* A strongly-typed, structured `read_state` path.
|
|
37
|
+
*
|
|
38
|
+
* Builders for the well-known paths are available on {@link StatePaths}, e.g. {@link StatePaths.time}
|
|
39
|
+
* is a `KnownPath<Date>` and {@link StatePaths.canisterControllers} builds a `KnownPath<Principal[]>`
|
|
40
|
+
* for a given canister. Construct your own for arbitrary paths: `path` is the fully-formed sequence
|
|
41
|
+
* of label segments (strings are UTF-8 encoded), including any `['canister', <id>]` or
|
|
42
|
+
* `['subnet', <id>]` prefix.
|
|
43
|
+
*
|
|
44
|
+
* The value at the path is decoded with the `decode` function, and looked up from the response
|
|
45
|
+
* by passing the instance to {@link StateValues.get}.
|
|
46
|
+
* @template T the type produced by decoding the value at this path
|
|
47
|
+
*/
|
|
48
|
+
export declare class KnownPath<T> {
|
|
49
|
+
readonly decode: (bytes: Uint8Array) => T;
|
|
50
|
+
/**
|
|
51
|
+
* A unique token identifying this path in {@link StateValues}.
|
|
52
|
+
*/
|
|
53
|
+
readonly key: symbol;
|
|
54
|
+
readonly path: Uint8Array[];
|
|
55
|
+
constructor(path: (Uint8Array | string)[] | Uint8Array | string, decode: (bytes: Uint8Array) => T);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* A `read_state` path defined by the user, with a string {@link DecodeStrategy}. Consumed by the
|
|
59
|
+
* status utilities (e.g. `CanisterStatus.request`), which translate it into a {@link KnownPath}
|
|
60
|
+
* before calling `Agent.readState`.
|
|
37
61
|
* @param {string} key the key to use to access the returned value in the status map
|
|
38
|
-
* @param {Uint8Array[]} path the path to the desired value
|
|
39
|
-
* @param {
|
|
62
|
+
* @param {Uint8Array[] | Uint8Array | string} path the path to the desired value
|
|
63
|
+
* @param {DecodeStrategy} decodeStrategy the strategy used to decode the returned value
|
|
64
|
+
* @deprecated Use {@link KnownPath} with `Agent.readState` instead.
|
|
40
65
|
*/
|
|
41
|
-
export declare class CustomPath
|
|
66
|
+
export declare class CustomPath {
|
|
42
67
|
key: string;
|
|
43
68
|
path: Uint8Array[] | Uint8Array | string;
|
|
44
69
|
decodeStrategy: DecodeStrategy;
|
|
45
70
|
constructor(key: string, path: Uint8Array[] | Uint8Array | string, decodeStrategy: DecodeStrategy);
|
|
46
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* A path to read from the `read_state` endpoint.
|
|
74
|
+
*
|
|
75
|
+
* May be a {@link KnownPath} (see {@link StatePaths} for the well-known ones) or a raw encoded
|
|
76
|
+
* path (an array of buffers) which is passed through unchanged.
|
|
77
|
+
* `Agent.readState` accepts these directly, encoding them internally.
|
|
78
|
+
*/
|
|
79
|
+
export type Path = KnownPath<unknown> | Uint8Array[];
|
|
80
|
+
/**
|
|
81
|
+
* Builders for the well-known state paths, producing {@link KnownPath}s accepted directly
|
|
82
|
+
* by `Agent.readState`.
|
|
83
|
+
*
|
|
84
|
+
* The `canister*` and `subnet*` entries are functions taking the target ID, since it is baked into
|
|
85
|
+
* the path. Pass the `subnet*` paths when reading state from a subnet (`readState({ subnetId }, …)`)
|
|
86
|
+
* and the `canister*` paths when reading from a canister.
|
|
87
|
+
*/
|
|
88
|
+
export declare const StatePaths: {
|
|
89
|
+
/** The canister's or subnet's time, as a {@link Date}. */
|
|
90
|
+
readonly time: KnownPath<Date>;
|
|
91
|
+
/**
|
|
92
|
+
* The given canister's controllers, as {@link Principal}s.
|
|
93
|
+
* @param canisterId the canister to scope the path to
|
|
94
|
+
*/
|
|
95
|
+
readonly canisterControllers: (canisterId: Principal) => KnownPath<Principal[]>;
|
|
96
|
+
/**
|
|
97
|
+
* The given canister's module hash.
|
|
98
|
+
* @param canisterId the canister to scope the path to
|
|
99
|
+
*/
|
|
100
|
+
readonly canisterModuleHash: (canisterId: Principal) => KnownPath<Uint8Array>;
|
|
101
|
+
/**
|
|
102
|
+
* The given canister's `candid:service` metadata, as a UTF-8 string.
|
|
103
|
+
* @param canisterId the canister to scope the path to
|
|
104
|
+
*/
|
|
105
|
+
readonly canisterCandid: (canisterId: Principal) => KnownPath<string>;
|
|
106
|
+
/**
|
|
107
|
+
* The given canister's metadata entry, as a UTF-8 string.
|
|
108
|
+
* @param canisterId the canister to scope the path to
|
|
109
|
+
* @param key the metadata key to read
|
|
110
|
+
*/
|
|
111
|
+
readonly canisterMetadataString: (canisterId: Principal, key: string) => KnownPath<string>;
|
|
112
|
+
/**
|
|
113
|
+
* The given subnet's canister ID ranges.
|
|
114
|
+
* @param subnetId the subnet to scope the path to
|
|
115
|
+
*/
|
|
116
|
+
readonly subnetCanisterRanges: (subnetId: Principal) => KnownPath<CanisterRanges>;
|
|
117
|
+
/**
|
|
118
|
+
* The given subnet's public key, as raw bytes.
|
|
119
|
+
* @param subnetId the subnet to scope the path to
|
|
120
|
+
*/
|
|
121
|
+
readonly subnetPublicKey: (subnetId: Principal) => KnownPath<Uint8Array>;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* The decoded values returned by `Agent.readState`, keyed by {@link KnownPath}.
|
|
125
|
+
* Look values up by passing the same {@link KnownPath} instance that
|
|
126
|
+
* was requested; the return type follows the path's type parameter.
|
|
127
|
+
*/
|
|
128
|
+
export declare class StateValues {
|
|
129
|
+
#private;
|
|
130
|
+
constructor(values?: Map<symbol, unknown>);
|
|
131
|
+
/**
|
|
132
|
+
* The decoded value for `path`, or `null` if it was absent from the certificate or not requested.
|
|
133
|
+
* @param path the {@link KnownPath} whose value to read
|
|
134
|
+
*/
|
|
135
|
+
get<T>(path: KnownPath<T>): T | null;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Encode a {@link Path} into the raw path expected by the `read_state` endpoint.
|
|
139
|
+
* @param path the path to encode
|
|
140
|
+
* @returns the encoded path, as an array of buffers
|
|
141
|
+
*/
|
|
142
|
+
export declare function encodePath(path: Path): Uint8Array[];
|
|
47
143
|
/**
|
|
48
144
|
* Decode a value based on the specified strategy
|
|
49
145
|
* @param data the raw data to decode
|
|
@@ -57,13 +153,6 @@ export declare function decodeValue(data: Uint8Array, strategy: DecodeStrategy):
|
|
|
57
153
|
* @returns an array of principal IDs
|
|
58
154
|
*/
|
|
59
155
|
export declare function decodeControllers(buf: Uint8Array): Principal[];
|
|
60
|
-
/**
|
|
61
|
-
* Encode a metadata path for canister metadata queries
|
|
62
|
-
* @param metaPath the metadata path (string or Uint8Array)
|
|
63
|
-
* @param canisterUint8Array the canister ID as Uint8Array
|
|
64
|
-
* @returns the encoded path
|
|
65
|
-
*/
|
|
66
|
-
export declare function encodeMetadataPath(metaPath: string | Uint8Array, canisterUint8Array: Uint8Array): Uint8Array[];
|
|
67
156
|
/**
|
|
68
157
|
* Check if a path object has custom path signature (has 'key' and 'path' properties)
|
|
69
158
|
* @param path the path to check
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readState.d.ts","sourceRoot":"","sources":["../../../../src/agent/utils/readState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAIvC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EACL,KAAK,IAAI,
|
|
1
|
+
{"version":3,"file":"readState.d.ts","sourceRoot":"","sources":["../../../../src/agent/utils/readState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAIvC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EACL,KAAK,IAAI,EACT,KAAK,cAAc,EAQpB,MAAM,mBAAmB,CAAC;AAS3B;;GAEG;AACH,eAAO,MAAM,iBAAiB,WAE7B,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,GAAG,CAAC,M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3
|
-
import { decodeLeb128 } from "../utils/leb.js";
|
|
3
|
+
import { decodeLeb128, decodeTime } from "../utils/leb.js";
|
|
4
4
|
import { bytesToHex, utf8ToBytes } from '@noble/hashes/utils.js';
|
|
5
|
-
import { flatten_forks, LookupPathStatus, lookup_path, lookup_subtree, LookupSubtreeStatus, } from "../certificate.js";
|
|
5
|
+
import { decodeCanisterRanges, flatten_forks, LookupPathStatus, lookup_path, lookup_subtree, LookupSubtreeStatus, } from "../certificate.js";
|
|
6
6
|
import { LookupErrorCode, DerKeyLengthMismatchErrorCode, ProtocolError, UnknownError, HashTreeDecodeErrorCode, } from "../errors.js";
|
|
7
7
|
/**
|
|
8
8
|
* The root subnet ID for IC mainnet
|
|
9
9
|
*/
|
|
10
10
|
export const IC_ROOT_SUBNET_ID = Principal.fromText('tdb26-jop6k-aogll-7ltgs-eruif-6kk7m-qpktf-gdiqx-mxtrf-vb5e6-eqe');
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* A strongly-typed, structured `read_state` path.
|
|
13
|
+
*
|
|
14
|
+
* Builders for the well-known paths are available on {@link StatePaths}, e.g. {@link StatePaths.time}
|
|
15
|
+
* is a `KnownPath<Date>` and {@link StatePaths.canisterControllers} builds a `KnownPath<Principal[]>`
|
|
16
|
+
* for a given canister. Construct your own for arbitrary paths: `path` is the fully-formed sequence
|
|
17
|
+
* of label segments (strings are UTF-8 encoded), including any `['canister', <id>]` or
|
|
18
|
+
* `['subnet', <id>]` prefix.
|
|
19
|
+
*
|
|
20
|
+
* The value at the path is decoded with the `decode` function, and looked up from the response
|
|
21
|
+
* by passing the instance to {@link StateValues.get}.
|
|
22
|
+
* @template T the type produced by decoding the value at this path
|
|
23
|
+
*/
|
|
24
|
+
export class KnownPath {
|
|
25
|
+
constructor(path, decode) {
|
|
26
|
+
this.decode = decode;
|
|
27
|
+
/**
|
|
28
|
+
* A unique token identifying this path in {@link StateValues}.
|
|
29
|
+
*/
|
|
30
|
+
this.key = Symbol();
|
|
31
|
+
const segments = Array.isArray(path) ? path : [path];
|
|
32
|
+
this.path = segments.map(segment => typeof segment === 'string' ? utf8ToBytes(segment) : segment);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A `read_state` path defined by the user, with a string {@link DecodeStrategy}. Consumed by the
|
|
37
|
+
* status utilities (e.g. `CanisterStatus.request`), which translate it into a {@link KnownPath}
|
|
38
|
+
* before calling `Agent.readState`.
|
|
13
39
|
* @param {string} key the key to use to access the returned value in the status map
|
|
14
|
-
* @param {Uint8Array[]} path the path to the desired value
|
|
15
|
-
* @param {
|
|
40
|
+
* @param {Uint8Array[] | Uint8Array | string} path the path to the desired value
|
|
41
|
+
* @param {DecodeStrategy} decodeStrategy the strategy used to decode the returned value
|
|
42
|
+
* @deprecated Use {@link KnownPath} with `Agent.readState` instead.
|
|
16
43
|
*/
|
|
17
44
|
export class CustomPath {
|
|
18
45
|
constructor(key, path, decodeStrategy) {
|
|
@@ -21,6 +48,76 @@ export class CustomPath {
|
|
|
21
48
|
this.decodeStrategy = decodeStrategy;
|
|
22
49
|
}
|
|
23
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Builders for the well-known state paths, producing {@link KnownPath}s accepted directly
|
|
53
|
+
* by `Agent.readState`.
|
|
54
|
+
*
|
|
55
|
+
* The `canister*` and `subnet*` entries are functions taking the target ID, since it is baked into
|
|
56
|
+
* the path. Pass the `subnet*` paths when reading state from a subnet (`readState({ subnetId }, …)`)
|
|
57
|
+
* and the `canister*` paths when reading from a canister.
|
|
58
|
+
*/
|
|
59
|
+
export const StatePaths = {
|
|
60
|
+
/** The canister's or subnet's time, as a {@link Date}. */
|
|
61
|
+
time: new KnownPath(['time'], decodeTime),
|
|
62
|
+
/**
|
|
63
|
+
* The given canister's controllers, as {@link Principal}s.
|
|
64
|
+
* @param canisterId the canister to scope the path to
|
|
65
|
+
*/
|
|
66
|
+
canisterControllers: (canisterId) => new KnownPath(['canister', canisterId.toUint8Array(), 'controllers'], decodeControllers),
|
|
67
|
+
/**
|
|
68
|
+
* The given canister's module hash.
|
|
69
|
+
* @param canisterId the canister to scope the path to
|
|
70
|
+
*/
|
|
71
|
+
canisterModuleHash: (canisterId) => new KnownPath(['canister', canisterId.toUint8Array(), 'module_hash'], x => x),
|
|
72
|
+
/**
|
|
73
|
+
* The given canister's `candid:service` metadata, as a UTF-8 string.
|
|
74
|
+
* @param canisterId the canister to scope the path to
|
|
75
|
+
*/
|
|
76
|
+
canisterCandid: (canisterId) => StatePaths.canisterMetadataString(canisterId, 'candid:service'),
|
|
77
|
+
/**
|
|
78
|
+
* The given canister's metadata entry, as a UTF-8 string.
|
|
79
|
+
* @param canisterId the canister to scope the path to
|
|
80
|
+
* @param key the metadata key to read
|
|
81
|
+
*/
|
|
82
|
+
canisterMetadataString: (canisterId, key) => new KnownPath(['canister', canisterId.toUint8Array(), 'metadata', key], bytes => new TextDecoder().decode(bytes)),
|
|
83
|
+
/**
|
|
84
|
+
* The given subnet's canister ID ranges.
|
|
85
|
+
* @param subnetId the subnet to scope the path to
|
|
86
|
+
*/
|
|
87
|
+
subnetCanisterRanges: (subnetId) => new KnownPath(['subnet', subnetId.toUint8Array(), 'canister_ranges'], decodeCanisterRanges),
|
|
88
|
+
/**
|
|
89
|
+
* The given subnet's public key, as raw bytes.
|
|
90
|
+
* @param subnetId the subnet to scope the path to
|
|
91
|
+
*/
|
|
92
|
+
subnetPublicKey: (subnetId) => new KnownPath(['subnet', subnetId.toUint8Array(), 'public_key'], bytes => bytes),
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* The decoded values returned by `Agent.readState`, keyed by {@link KnownPath}.
|
|
96
|
+
* Look values up by passing the same {@link KnownPath} instance that
|
|
97
|
+
* was requested; the return type follows the path's type parameter.
|
|
98
|
+
*/
|
|
99
|
+
export class StateValues {
|
|
100
|
+
#values;
|
|
101
|
+
constructor(values = new Map()) {
|
|
102
|
+
this.#values = values;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* The decoded value for `path`, or `null` if it was absent from the certificate or not requested.
|
|
106
|
+
* @param path the {@link KnownPath} whose value to read
|
|
107
|
+
*/
|
|
108
|
+
get(path) {
|
|
109
|
+
return (this.#values.get(path.key) ?? null);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Encode a {@link Path} into the raw path expected by the `read_state` endpoint.
|
|
114
|
+
* @param path the path to encode
|
|
115
|
+
* @returns the encoded path, as an array of buffers
|
|
116
|
+
*/
|
|
117
|
+
export function encodePath(path) {
|
|
118
|
+
// A raw encoded path passes through unchanged; a KnownPath is already fully-formed.
|
|
119
|
+
return Array.isArray(path) ? path : path.path;
|
|
120
|
+
}
|
|
24
121
|
/**
|
|
25
122
|
* Decode a value based on the specified strategy
|
|
26
123
|
* @param data the raw data to decode
|
|
@@ -52,16 +149,6 @@ export function decodeControllers(buf) {
|
|
|
52
149
|
return Principal.fromUint8Array(buf);
|
|
53
150
|
});
|
|
54
151
|
}
|
|
55
|
-
/**
|
|
56
|
-
* Encode a metadata path for canister metadata queries
|
|
57
|
-
* @param metaPath the metadata path (string or Uint8Array)
|
|
58
|
-
* @param canisterUint8Array the canister ID as Uint8Array
|
|
59
|
-
* @returns the encoded path
|
|
60
|
-
*/
|
|
61
|
-
export function encodeMetadataPath(metaPath, canisterUint8Array) {
|
|
62
|
-
const encoded = typeof metaPath === 'string' ? utf8ToBytes(metaPath) : metaPath;
|
|
63
|
-
return [utf8ToBytes('canister'), canisterUint8Array, utf8ToBytes('metadata'), encoded];
|
|
64
|
-
}
|
|
65
152
|
/**
|
|
66
153
|
* Check if a path object has custom path signature (has 'key' and 'path' properties)
|
|
67
154
|
* @param path the path to check
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"readState.js","sourceRoot":"","sources":["../../../../src/agent/utils/readState.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,KA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