@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.
Files changed (55) hide show
  1. package/lib/cjs/agent/agent/api.d.ts +52 -4
  2. package/lib/cjs/agent/agent/api.d.ts.map +1 -1
  3. package/lib/cjs/agent/agent/api.js +6 -1
  4. package/lib/cjs/agent/agent/api.js.map +1 -1
  5. package/lib/cjs/agent/agent/http/index.d.ts +2 -2
  6. package/lib/cjs/agent/agent/http/index.d.ts.map +1 -1
  7. package/lib/cjs/agent/agent/http/index.js +41 -17
  8. package/lib/cjs/agent/agent/http/index.js.map +1 -1
  9. package/lib/cjs/agent/canisterStatus/index.d.ts +2 -3
  10. package/lib/cjs/agent/canisterStatus/index.d.ts.map +1 -1
  11. package/lib/cjs/agent/canisterStatus/index.js +63 -120
  12. package/lib/cjs/agent/canisterStatus/index.js.map +1 -1
  13. package/lib/cjs/agent/certificate.d.ts +1 -1
  14. package/lib/cjs/agent/certificate.d.ts.map +1 -1
  15. package/lib/cjs/agent/certificate.js.map +1 -1
  16. package/lib/cjs/agent/polling/index.d.ts +4 -3
  17. package/lib/cjs/agent/polling/index.d.ts.map +1 -1
  18. package/lib/cjs/agent/polling/index.js +5 -13
  19. package/lib/cjs/agent/polling/index.js.map +1 -1
  20. package/lib/cjs/agent/subnetStatus/index.d.ts +3 -2
  21. package/lib/cjs/agent/subnetStatus/index.d.ts.map +1 -1
  22. package/lib/cjs/agent/subnetStatus/index.js +59 -82
  23. package/lib/cjs/agent/subnetStatus/index.js.map +1 -1
  24. package/lib/cjs/agent/utils/readState.d.ts +102 -13
  25. package/lib/cjs/agent/utils/readState.d.ts.map +1 -1
  26. package/lib/cjs/agent/utils/readState.js +104 -15
  27. package/lib/cjs/agent/utils/readState.js.map +1 -1
  28. package/lib/esm/agent/agent/api.d.ts +52 -4
  29. package/lib/esm/agent/agent/api.d.ts.map +1 -1
  30. package/lib/esm/agent/agent/api.js +1 -0
  31. package/lib/esm/agent/agent/api.js.map +1 -1
  32. package/lib/esm/agent/agent/http/index.d.ts +2 -2
  33. package/lib/esm/agent/agent/http/index.d.ts.map +1 -1
  34. package/lib/esm/agent/agent/http/index.js +42 -18
  35. package/lib/esm/agent/agent/http/index.js.map +1 -1
  36. package/lib/esm/agent/canisterStatus/index.d.ts +2 -3
  37. package/lib/esm/agent/canisterStatus/index.d.ts.map +1 -1
  38. package/lib/esm/agent/canisterStatus/index.js +65 -121
  39. package/lib/esm/agent/canisterStatus/index.js.map +1 -1
  40. package/lib/esm/agent/certificate.d.ts +1 -1
  41. package/lib/esm/agent/certificate.d.ts.map +1 -1
  42. package/lib/esm/agent/certificate.js.map +1 -1
  43. package/lib/esm/agent/polling/index.d.ts +4 -3
  44. package/lib/esm/agent/polling/index.d.ts.map +1 -1
  45. package/lib/esm/agent/polling/index.js +7 -15
  46. package/lib/esm/agent/polling/index.js.map +1 -1
  47. package/lib/esm/agent/subnetStatus/index.d.ts +3 -2
  48. package/lib/esm/agent/subnetStatus/index.d.ts.map +1 -1
  49. package/lib/esm/agent/subnetStatus/index.js +62 -85
  50. package/lib/esm/agent/subnetStatus/index.js.map +1 -1
  51. package/lib/esm/agent/utils/readState.d.ts +102 -13
  52. package/lib/esm/agent/utils/readState.d.ts.map +1 -1
  53. package/lib/esm/agent/utils/readState.js +102 -15
  54. package/lib/esm/agent/utils/readState.js.map +1 -1
  55. package/package.json +1 -1
@@ -41,19 +41,48 @@ const _principal_1 = require("../../principal/index.js");
41
41
  const errors_ts_1 = require("../errors.js");
42
42
  const certificate_ts_1 = require("../certificate.js");
43
43
  const cbor = __importStar(require("../cbor.js"));
44
- const leb_ts_1 = require("../utils/leb.js");
45
44
  const utils_js_1 = require("@noble/hashes/utils.js");
46
45
  const readState_ts_1 = require("../utils/readState.js");
47
46
  // Re-export shared types and functions
48
47
  var readState_ts_2 = require("../utils/readState.js");
49
48
  Object.defineProperty(exports, "CustomPath", { enumerable: true, get: function () { return readState_ts_2.CustomPath; } });
50
49
  Object.defineProperty(exports, "IC_ROOT_SUBNET_ID", { enumerable: true, get: function () { return readState_ts_2.IC_ROOT_SUBNET_ID; } });
50
+ /**
51
+ * Build the {@link KnownPath} for a named (non-`nodeKeys`) subnet status path. `nodeKeys` is handled
52
+ * separately, as its value is derived from the raw certificate.
53
+ * @param path the named subnet status path
54
+ * @param subnetId the subnet the request targets
55
+ */
56
+ const namedToKnown = (path, subnetId) => {
57
+ switch (path) {
58
+ case 'time':
59
+ return readState_ts_1.StatePaths.time;
60
+ case 'publicKey':
61
+ return readState_ts_1.StatePaths.subnetPublicKey(subnetId);
62
+ case 'canisterRanges':
63
+ return readState_ts_1.StatePaths.subnetCanisterRanges(subnetId);
64
+ }
65
+ };
66
+ /**
67
+ * Translate a user-provided {@link CustomPath} into a {@link KnownPath} that {@link HttpAgent.readState}
68
+ * can encode and decode. A string or single-buffer path names a segment under the subnet subtree.
69
+ * @param custom the user-provided custom path
70
+ * @param subnetId the subnet to scope a simple path to
71
+ */
72
+ const customToKnown = (custom, subnetId) => {
73
+ const decode = (bytes) => (0, readState_ts_1.decodeValue)(bytes, custom.decodeStrategy);
74
+ if (typeof custom.path === 'string' || custom.path instanceof Uint8Array) {
75
+ return new readState_ts_1.KnownPath(['subnet', subnetId.toUint8Array(), custom.path], decode);
76
+ }
77
+ return new readState_ts_1.KnownPath(custom.path, decode);
78
+ };
51
79
  /**
52
80
  * Requests information from a subnet's `read_state` endpoint.
53
81
  * Can be used to request information about the subnet's time, canister ranges, public key, node keys, and metrics.
54
82
  * @param {SubnetStatusOptions} options The configuration for the subnet status request.
55
83
  * @see {@link SubnetStatusOptions} for detailed options.
56
84
  * @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.
85
+ * @deprecated Use {@link HttpAgent.readState} directly with {@link StatePaths} instead. This function will be removed in a future release.
57
86
  * @example
58
87
  * const status = await subnetStatus.request({
59
88
  * subnetId: IC_ROOT_SUBNET_ID,
@@ -67,91 +96,38 @@ Object.defineProperty(exports, "IC_ROOT_SUBNET_ID", { enumerable: true, get: fun
67
96
  async function request(options) {
68
97
  const { agent, paths, disableCertificateTimeVerification = false } = options;
69
98
  const subnetId = _principal_1.Principal.from(options.subnetId);
70
- const uniquePaths = [...new Set(paths)];
99
+ const uniquePaths = [...new Set(paths ?? [])];
71
100
  const status = new Map();
72
- const promises = uniquePaths.map((path, index) => {
73
- const encodedPath = encodePath(path, subnetId);
74
- return (async () => {
75
- try {
76
- if (agent.rootKey === null) {
77
- throw errors_ts_1.ExternalError.fromCode(new errors_ts_1.MissingRootKeyErrorCode());
78
- }
79
- const rootKey = agent.rootKey;
80
- const response = await agent.readSubnetState(subnetId, {
81
- paths: [encodedPath],
82
- });
83
- const certificate = await certificate_ts_1.Certificate.create({
84
- certificate: response.certificate,
85
- rootKey,
86
- principal: { subnetId },
101
+ const keyOf = (path) => (typeof path === 'string' ? path : path.key);
102
+ const promises = uniquePaths.map(async (path) => {
103
+ try {
104
+ // The nodeKeys path resolves to per-node public keys, which require parsing the raw certificate.
105
+ if (path === 'nodeKeys') {
106
+ const { verifiedCertificate } = await agent.readState({ subnetId }, {
107
+ paths: [[(0, utils_js_1.utf8ToBytes)('subnet'), subnetId.toUint8Array(), (0, utils_js_1.utf8ToBytes)('node')]],
87
108
  disableTimeVerification: disableCertificateTimeVerification,
88
- agent,
89
109
  });
90
- const lookup = (cert, lookupPath) => {
91
- if (lookupPath === 'nodeKeys') {
92
- // For node keys, we need to parse the certificate directly
93
- const data = (0, readState_ts_1.lookupNodeKeysFromCertificate)(cert.cert, subnetId);
94
- return {
95
- path: lookupPath,
96
- data,
97
- };
98
- }
99
- return {
100
- path: lookupPath,
101
- data: (0, certificate_ts_1.lookupResultToBuffer)(cert.lookup_path(encodedPath)),
102
- };
103
- };
104
- const { path, data } = lookup(certificate, uniquePaths[index]);
105
- if (!data) {
106
- if (typeof path === 'string') {
107
- status.set(path, null);
108
- }
109
- else {
110
- status.set(path.key, null);
111
- }
112
- }
113
- else {
114
- switch (path) {
115
- case 'time': {
116
- status.set(path, (0, leb_ts_1.decodeTime)(data));
117
- break;
118
- }
119
- case 'canisterRanges': {
120
- status.set(path, (0, certificate_ts_1.decodeCanisterRanges)(data));
121
- break;
122
- }
123
- case 'publicKey': {
124
- status.set(path, data);
125
- break;
126
- }
127
- case 'nodeKeys': {
128
- status.set(path, data);
129
- break;
130
- }
131
- default: {
132
- // Check for CustomPath signature
133
- if ((0, readState_ts_1.isCustomPath)(path)) {
134
- status.set(path.key, (0, readState_ts_1.decodeValue)(data, path.decodeStrategy));
135
- }
136
- }
137
- }
138
- }
110
+ status.set('nodeKeys', (0, readState_ts_1.lookupNodeKeysFromCertificate)(verifiedCertificate.cert, subnetId));
111
+ return;
139
112
  }
140
- catch (error) {
141
- // Throw on certificate errors
142
- if (error instanceof errors_ts_1.AgentError &&
143
- (error.hasCode(errors_ts_1.CertificateVerificationErrorCode) ||
144
- error.hasCode(errors_ts_1.CertificateTimeErrorCode))) {
145
- throw error;
146
- }
147
- if ((0, readState_ts_1.isCustomPath)(path)) {
148
- status.set(path.key, null);
149
- }
150
- else {
151
- status.set(path, null);
152
- }
113
+ // Translate to a KnownPath and let readState encode and decode it.
114
+ const known = typeof path === 'string' ? namedToKnown(path, subnetId) : customToKnown(path, subnetId);
115
+ const { values } = await agent.readState({ subnetId }, {
116
+ paths: [known],
117
+ disableTimeVerification: disableCertificateTimeVerification,
118
+ });
119
+ status.set(keyOf(path), values.get(known));
120
+ }
121
+ catch (error) {
122
+ // Throw on certificate errors
123
+ if (error instanceof errors_ts_1.AgentError &&
124
+ (error.hasCode(errors_ts_1.CertificateVerificationErrorCode) ||
125
+ error.hasCode(errors_ts_1.CertificateTimeErrorCode) ||
126
+ error.hasCode(errors_ts_1.MissingRootKeyErrorCode))) {
127
+ throw error;
153
128
  }
154
- })();
129
+ status.set(keyOf(path), null);
130
+ }
155
131
  });
156
132
  // Fetch all values separately, as each option can fail
157
133
  await Promise.all(promises);
@@ -182,6 +158,7 @@ function lookupSubnetPublicKey(certificate, subnetId) {
182
158
  }
183
159
  /**
184
160
  * Encode a path for subnet state queries
161
+ * @deprecated Use {@link HttpAgent.readState} directly with {@link StatePaths} instead
185
162
  * @param path the path to encode
186
163
  * @param subnetId the subnet ID
187
164
  * @returns the encoded path as an array of Uint8Arrays
@@ -192,7 +169,7 @@ function encodePath(path, subnetId) {
192
169
  case 'time':
193
170
  return [(0, utils_js_1.utf8ToBytes)('time')];
194
171
  case 'canisterRanges':
195
- return [(0, utils_js_1.utf8ToBytes)('canister_ranges'), subnetUint8Array];
172
+ return [(0, utils_js_1.utf8ToBytes)('subnet'), subnetUint8Array, (0, utils_js_1.utf8ToBytes)('canister_ranges')];
196
173
  case 'publicKey':
197
174
  return [(0, utils_js_1.utf8ToBytes)('subnet'), subnetUint8Array, (0, utils_js_1.utf8ToBytes)('public_key')];
198
175
  case 'nodeKeys':
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/agent/subnetStatus/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6FA,0BAoGC;AAQD,4CAUC;AAqBD,gCA8BC;AAtQD,2CAAuC;AACvC,4CAUsB;AAEtB,sDAQ2B;AAC3B,iDAAmC;AACnC,4CAA6C;AAC7C,qDAAqD;AAErD,wDAQ+B;AAE/B,uCAAuC;AACvC,sDAA2F;AAA7D,0GAAA,UAAU,OAAA;AAAE,iHAAA,iBAAiB,OAAA;AAwC3D;;;;;;;;;;;;;;;GAeG;AACI,KAAK,UAAU,OAAO,CAAC,OAA4B;IACxD,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,kCAAkC,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC;IAC7E,MAAM,QAAQ,GAAG,sBAAS,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAElD,MAAM,WAAW,GAAG,CAAC,GAAG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AA,sBAAW,EAAC,YAAY,CAAC,CAAC,CAAC;QAC9E,KAAK,UAAU;YACb,OAAO,CAAC,IAAA,sBAAW,EAAC,QAAQ,CAAC,EAAE,gBAAgB,EAAE,IAAA,sBAAW,EAAC,MAAM,CAAC,CAAC,CAAC;QACxE,OAAO,CAAC,CAAC,CAAC;YACR,iCAAiC;YACjC,IAAI,IAAA,2BAAY,EAAC,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,IAAA,sBAAW,EAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;oBAC9E,OAAO,CAAC,IAAA,sBAAW,EAAC,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,wBAAY,CAAC,QAAQ,CACzB,IAAI,+BAAmB,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 custom paths
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
- * Interface to define a custom path. Nested paths will be represented as individual buffers, and can be created from text using TextEncoder.
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, represented as an array of buffers
39
- * @param {string} decodeStrategy the strategy to use to decode the returned value
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 implements 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,EAOV,MAAM,mBAAmB,CAAC;AAS3B;;GAEG;AACH,eAAO,MAAM,iBAAiB,WAE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EAAE,QAAQ,EAAE,cAAc,GAAG,UAAU,CAalF;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,UAAU,GAAG,SAAS,EAAE,CAK9D;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,OAAO,CAAA;CAAE,CAEnF;AAED;;;;;;GAMG;AACH,wBAAgB,6BAA6B,CAC3C,WAAW,EAAE,IAAI,EACjB,QAAQ,EAAE,SAAS,GAClB,cAAc,CAoChB"}
@@ -33,10 +33,10 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.CustomPath = exports.IC_ROOT_SUBNET_ID = void 0;
36
+ exports.StateValues = exports.StatePaths = exports.CustomPath = exports.KnownPath = exports.IC_ROOT_SUBNET_ID = void 0;
37
+ exports.encodePath = encodePath;
37
38
  exports.decodeValue = decodeValue;
38
39
  exports.decodeControllers = decodeControllers;
39
- exports.encodeMetadataPath = encodeMetadataPath;
40
40
  exports.isCustomPath = isCustomPath;
41
41
  exports.lookupNodeKeysFromCertificate = lookupNodeKeysFromCertificate;
42
42
  const _principal_1 = require("../../principal/index.js");
@@ -50,10 +50,38 @@ const errors_ts_1 = require("../errors.js");
50
50
  */
51
51
  exports.IC_ROOT_SUBNET_ID = _principal_1.Principal.fromText('tdb26-jop6k-aogll-7ltgs-eruif-6kk7m-qpktf-gdiqx-mxtrf-vb5e6-eqe');
52
52
  /**
53
- * Interface to define a custom path. Nested paths will be represented as individual buffers, and can be created from text using TextEncoder.
53
+ * A strongly-typed, structured `read_state` path.
54
+ *
55
+ * Builders for the well-known paths are available on {@link StatePaths}, e.g. {@link StatePaths.time}
56
+ * is a `KnownPath<Date>` and {@link StatePaths.canisterControllers} builds a `KnownPath<Principal[]>`
57
+ * for a given canister. Construct your own for arbitrary paths: `path` is the fully-formed sequence
58
+ * of label segments (strings are UTF-8 encoded), including any `['canister', <id>]` or
59
+ * `['subnet', <id>]` prefix.
60
+ *
61
+ * The value at the path is decoded with the `decode` function, and looked up from the response
62
+ * by passing the instance to {@link StateValues.get}.
63
+ * @template T the type produced by decoding the value at this path
64
+ */
65
+ class KnownPath {
66
+ constructor(path, decode) {
67
+ this.decode = decode;
68
+ /**
69
+ * A unique token identifying this path in {@link StateValues}.
70
+ */
71
+ this.key = Symbol();
72
+ const segments = Array.isArray(path) ? path : [path];
73
+ this.path = segments.map(segment => typeof segment === 'string' ? (0, utils_js_1.utf8ToBytes)(segment) : segment);
74
+ }
75
+ }
76
+ exports.KnownPath = KnownPath;
77
+ /**
78
+ * A `read_state` path defined by the user, with a string {@link DecodeStrategy}. Consumed by the
79
+ * status utilities (e.g. `CanisterStatus.request`), which translate it into a {@link KnownPath}
80
+ * before calling `Agent.readState`.
54
81
  * @param {string} key the key to use to access the returned value in the status map
55
- * @param {Uint8Array[]} path the path to the desired value, represented as an array of buffers
56
- * @param {string} decodeStrategy the strategy to use to decode the returned value
82
+ * @param {Uint8Array[] | Uint8Array | string} path the path to the desired value
83
+ * @param {DecodeStrategy} decodeStrategy the strategy used to decode the returned value
84
+ * @deprecated Use {@link KnownPath} with `Agent.readState` instead.
57
85
  */
58
86
  class CustomPath {
59
87
  constructor(key, path, decodeStrategy) {
@@ -63,6 +91,77 @@ class CustomPath {
63
91
  }
64
92
  }
65
93
  exports.CustomPath = CustomPath;
94
+ /**
95
+ * Builders for the well-known state paths, producing {@link KnownPath}s accepted directly
96
+ * by `Agent.readState`.
97
+ *
98
+ * The `canister*` and `subnet*` entries are functions taking the target ID, since it is baked into
99
+ * the path. Pass the `subnet*` paths when reading state from a subnet (`readState({ subnetId }, …)`)
100
+ * and the `canister*` paths when reading from a canister.
101
+ */
102
+ exports.StatePaths = {
103
+ /** The canister's or subnet's time, as a {@link Date}. */
104
+ time: new KnownPath(['time'], leb_ts_1.decodeTime),
105
+ /**
106
+ * The given canister's controllers, as {@link Principal}s.
107
+ * @param canisterId the canister to scope the path to
108
+ */
109
+ canisterControllers: (canisterId) => new KnownPath(['canister', canisterId.toUint8Array(), 'controllers'], decodeControllers),
110
+ /**
111
+ * The given canister's module hash.
112
+ * @param canisterId the canister to scope the path to
113
+ */
114
+ canisterModuleHash: (canisterId) => new KnownPath(['canister', canisterId.toUint8Array(), 'module_hash'], x => x),
115
+ /**
116
+ * The given canister's `candid:service` metadata, as a UTF-8 string.
117
+ * @param canisterId the canister to scope the path to
118
+ */
119
+ canisterCandid: (canisterId) => exports.StatePaths.canisterMetadataString(canisterId, 'candid:service'),
120
+ /**
121
+ * The given canister's metadata entry, as a UTF-8 string.
122
+ * @param canisterId the canister to scope the path to
123
+ * @param key the metadata key to read
124
+ */
125
+ canisterMetadataString: (canisterId, key) => new KnownPath(['canister', canisterId.toUint8Array(), 'metadata', key], bytes => new TextDecoder().decode(bytes)),
126
+ /**
127
+ * The given subnet's canister ID ranges.
128
+ * @param subnetId the subnet to scope the path to
129
+ */
130
+ subnetCanisterRanges: (subnetId) => new KnownPath(['subnet', subnetId.toUint8Array(), 'canister_ranges'], certificate_ts_1.decodeCanisterRanges),
131
+ /**
132
+ * The given subnet's public key, as raw bytes.
133
+ * @param subnetId the subnet to scope the path to
134
+ */
135
+ subnetPublicKey: (subnetId) => new KnownPath(['subnet', subnetId.toUint8Array(), 'public_key'], bytes => bytes),
136
+ };
137
+ /**
138
+ * The decoded values returned by `Agent.readState`, keyed by {@link KnownPath}.
139
+ * Look values up by passing the same {@link KnownPath} instance that
140
+ * was requested; the return type follows the path's type parameter.
141
+ */
142
+ class StateValues {
143
+ #values;
144
+ constructor(values = new Map()) {
145
+ this.#values = values;
146
+ }
147
+ /**
148
+ * The decoded value for `path`, or `null` if it was absent from the certificate or not requested.
149
+ * @param path the {@link KnownPath} whose value to read
150
+ */
151
+ get(path) {
152
+ return (this.#values.get(path.key) ?? null);
153
+ }
154
+ }
155
+ exports.StateValues = StateValues;
156
+ /**
157
+ * Encode a {@link Path} into the raw path expected by the `read_state` endpoint.
158
+ * @param path the path to encode
159
+ * @returns the encoded path, as an array of buffers
160
+ */
161
+ function encodePath(path) {
162
+ // A raw encoded path passes through unchanged; a KnownPath is already fully-formed.
163
+ return Array.isArray(path) ? path : path.path;
164
+ }
66
165
  /**
67
166
  * Decode a value based on the specified strategy
68
167
  * @param data the raw data to decode
@@ -94,16 +193,6 @@ function decodeControllers(buf) {
94
193
  return _principal_1.Principal.fromUint8Array(buf);
95
194
  });
96
195
  }
97
- /**
98
- * Encode a metadata path for canister metadata queries
99
- * @param metaPath the metadata path (string or Uint8Array)
100
- * @param canisterUint8Array the canister ID as Uint8Array
101
- * @returns the encoded path
102
- */
103
- function encodeMetadataPath(metaPath, canisterUint8Array) {
104
- const encoded = typeof metaPath === 'string' ? (0, utils_js_1.utf8ToBytes)(metaPath) : metaPath;
105
- return [(0, utils_js_1.utf8ToBytes)('canister'), canisterUint8Array, (0, utils_js_1.utf8ToBytes)('metadata'), encoded];
106
- }
107
196
  /**
108
197
  * Check if a path object has custom path signature (has 'key' and 'path' properties)
109
198
  * @param path the path to check
@@ -1 +1 @@
1
- {"version":3,"file":"readState.js","sourceRoot":"","sources":["../../../../src/agent/utils/readState.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuFA,kCAaC;AAOD,8CAKC;AAQD,gDAMC;AAOD,oCAEC;AASD,sEAuCC;AAvLD,2CAAuC;AACvC,iDAAmC;AACnC,4CAA+C;AAC/C,qDAAiE;AAEjE,sDAQ2B;AAC3B,4CAMsB;AAEtB;;GAEG;AACU,QAAA,iBAAiB,GAAG,sBAAS,CAAC,QAAQ,CACjD,iEAAiE,CAClE,CAAC;AAiCF;;;;;GAKG;AACH,MAAa,UAAU;IAIrB,YACE,GAAW,EACX,IAAwC,EACxC,cAA8B;QAE9B,IAAI,CAAC,GAAG,GAA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AI,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;QACjD,MAAM,qBAAqB,GAAG,IAAA,4BAAW,EAAC,CAAC,YAAY,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QACnE,IAAI,qBAAqB,CAAC,MAAM,KAAK,iCAAgB,CAAC,KAAK,EAAE,CAAC;YAC5D,MAAM,yBAAa,CAAC,QAAQ,CAC1B,IAAI,2BAAe,CAAC,sBAAsB,EAAE,qBAAqB,CAAC,MAAM,CAAC,CAC1E,CAAC;QACJ,CAAC;QAED,MAAM,mBAAmB,GAAG,qBAAqB,CAAC,KAAK,CAAC;QACxD,IAAI,mBAAmB,CAAC,UAAU,KAAK,EAAE,EAAE,CAAC;YAC1C,MAAM,yBAAa,CAAC,QAAQ,CAC1B,IAAI,yCAA6B,CAAC,EAAE,EAAE,mBAAmB,CAAC,UAAU,CAAC,CACtE,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,QAAQ,CAAC,GAAG,CAAC,OAAO,EAAE,mBAA0C,CAAC,CAAC;QACpE,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -4,6 +4,9 @@ import type { JsonObject } from '../../candid/index.js';
4
4
  import type { Identity } from '../auth.ts';
5
5
  import type { CallRequest, HttpHeaderField, QueryRequest } from './http/types.ts';
6
6
  import type { PollForResponseResult, PollingOptions } from '../polling/index.ts';
7
+ import type { Certificate, VerifyFunc } from '../certificate.ts';
8
+ import type { Path, StateValues } from '../utils/readState.ts';
9
+ export { KnownPath, StatePaths, StateValues, encodePath, type Path } from '../utils/readState.ts';
7
10
  /**
8
11
  * Codes used by the replica for rejecting a message.
9
12
  * See {@link https://sdk.dfinity.org/docs/interface-spec/#reject-codes | the interface spec}.
@@ -21,7 +24,36 @@ export declare enum ReplicaRejectCode {
21
24
  export interface ReadStateOptions {
22
25
  /**
23
26
  * A list of paths to read the state of.
27
+ *
28
+ * Each {@link Path} may be a raw encoded path (an array of buffers) or a {@link KnownPath}
29
+ * (see {@link import('../utils/readState.ts').StatePaths | StatePaths} for the well-known ones).
30
+ * KnownPaths are encoded internally, and their values are decoded into
31
+ * {@link ReadStateResponse.values}.
32
+ */
33
+ paths: Path[];
34
+ /**
35
+ * BLS verification strategy used to verify the returned certificate.
36
+ * Defaults to bls12_381 from `@noble/curves`.
37
+ */
38
+ blsVerify?: VerifyFunc;
39
+ /**
40
+ * The maximum age of the returned certificate in minutes, used for the freshness check.
41
+ * @default 5
42
+ */
43
+ maxAgeInMinutes?: number;
44
+ /**
45
+ * Skips the certificate freshness (time) check when verifying the returned certificate.
46
+ * Required for time-sync bootstrapping and for inspecting certificates when the local clock
47
+ * is known to be out of sync with the network.
48
+ * @default false
24
49
  */
50
+ disableTimeVerification?: boolean;
51
+ }
52
+ /**
53
+ * {@link ReadStateOptions} with every path already encoded to its raw form. Used by the low-level
54
+ * request builders ({@link Agent.createReadStateRequest}), which do not perform path encoding.
55
+ */
56
+ export interface ResolvedReadStateOptions extends Omit<ReadStateOptions, 'paths'> {
25
57
  paths: Uint8Array[][];
26
58
  }
27
59
  /**
@@ -130,6 +162,18 @@ export interface UpdateOptions extends CallOptions {
130
162
  }
131
163
  export interface ReadStateResponse {
132
164
  certificate: Uint8Array;
165
+ /**
166
+ * The parsed and verified {@link Certificate}, checked against the agent's root key and the
167
+ * effective target of the request. Unless {@link ReadStateOptions.disableTimeVerification} is
168
+ * set, verification includes the certificate freshness check.
169
+ */
170
+ verifiedCertificate: Certificate;
171
+ /**
172
+ * Decoded values for each requested {@link KnownPath}, looked up by passing the same KnownPath
173
+ * instance to {@link StateValues.get}. Each value is decoded with the path's
174
+ * {@link KnownPath.decode}. Raw (pre-encoded `Uint8Array[]`) paths are not decoded and are absent.
175
+ */
176
+ values: StateValues;
133
177
  }
134
178
  export interface v2ResponseBody {
135
179
  error_code?: string;
@@ -192,12 +236,16 @@ export interface Agent {
192
236
  * Create the request for the read state call.
193
237
  * `readState` uses this internally.
194
238
  * Useful to avoid signing the same request multiple times.
239
+ *
240
+ * Paths must already be encoded ({@link ResolvedReadStateOptions}); path resolution is done by
241
+ * {@link Agent.readState} before this is called.
195
242
  */
196
- createReadStateRequest?(options: ReadStateOptions, identity?: Identity): Promise<unknown>;
243
+ createReadStateRequest?(options: ResolvedReadStateOptions, identity?: Identity): Promise<unknown>;
197
244
  /**
198
- * Send a read state query to the replica. This includes a list of paths to return,
199
- * and will return a Certificate. This will only reject on communication errors,
200
- * but the certificate might contain less information than requested.
245
+ * Send a read state query to the replica, given a list of paths to return. Returns the raw
246
+ * certificate alongside a parsed {@link Certificate} that has been verified against the agent's
247
+ * root key and the effective target, rejecting on communication errors or if verification fails.
248
+ * The certificate might contain less information than requested.
201
249
  * @param effectiveTarget A Canister ID or Subnet ID related to this call.
202
250
  * @param options The options for this call.
203
251
  * @param identity Identity for the call. If not specified, uses the instance identity.