@icp-sdk/core 5.4.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/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 +71 -10
- 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 +9 -12
- package/lib/cjs/agent/agent/http/index.d.ts.map +1 -1
- package/lib/cjs/agent/agent/http/index.js +224 -176
- 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 +2 -3
- package/lib/cjs/agent/canisterStatus/index.d.ts.map +1 -1
- package/lib/cjs/agent/canisterStatus/index.js +65 -122
- 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 +6 -5
- 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 +7 -7
- package/lib/cjs/agent/polling/index.d.ts.map +1 -1
- package/lib/cjs/agent/polling/index.js +19 -20
- 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.d.ts +3 -2
- package/lib/cjs/agent/subnetStatus/index.d.ts.map +1 -1
- package/lib/cjs/agent/subnetStatus/index.js +65 -88
- 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 +104 -15
- package/lib/cjs/agent/utils/readState.d.ts.map +1 -1
- package/lib/cjs/agent/utils/readState.js +106 -17
- 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 +71 -10
- 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 +9 -12
- package/lib/esm/agent/agent/http/index.d.ts.map +1 -1
- package/lib/esm/agent/agent/http/index.js +218 -170
- 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 +2 -3
- package/lib/esm/agent/canisterStatus/index.d.ts.map +1 -1
- package/lib/esm/agent/canisterStatus/index.js +66 -122
- 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 +6 -5
- 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 +7 -7
- package/lib/esm/agent/polling/index.d.ts.map +1 -1
- package/lib/esm/agent/polling/index.js +19 -20
- 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.d.ts +3 -2
- package/lib/esm/agent/subnetStatus/index.d.ts.map +1 -1
- package/lib/esm/agent/subnetStatus/index.js +63 -86
- 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 +104 -15
- package/lib/esm/agent/utils/readState.d.ts.map +1 -1
- package/lib/esm/agent/utils/readState.js +103 -16
- 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,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
|
-
path: Uint8Array[] | string;
|
|
68
|
+
path: Uint8Array[] | Uint8Array | string;
|
|
44
69
|
decodeStrategy: DecodeStrategy;
|
|
45
|
-
constructor(key: string, path: Uint8Array[] | string, decodeStrategy: DecodeStrategy);
|
|
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,E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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"}
|
|
@@ -1,18 +1,45 @@
|
|
|
1
1
|
import { Principal } from '../../principal/index.js';
|
|
2
2
|
import * as cbor from "../cbor.js";
|
|
3
|
-
import { decodeLeb128 } from "../utils/leb.js";
|
|
4
|
-
import { bytesToHex, utf8ToBytes } from '@noble/hashes/utils';
|
|
5
|
-
import { flatten_forks, LookupPathStatus, lookup_path, lookup_subtree, LookupSubtreeStatus, } from "../certificate.js";
|
|
3
|
+
import { decodeLeb128, decodeTime } from "../utils/leb.js";
|
|
4
|
+
import { bytesToHex, utf8ToBytes } from '@noble/hashes/utils.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,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;
|
|
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,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAEjE,OAAO,EAGL,oBAAoB,EACpB,aAAa,EACb,gBAAgB,EAChB,WAAW,EACX,cAAc,EAEd,mBAAmB,GACpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,eAAe,EACf,6BAA6B,EAC7B,aAAa,EACb,YAAY,EACZ,uBAAuB,GACxB,MAAM,cAAc,CAAC;AAEtB;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,SAAS,CAAC,QAAQ,CACjD,iEAAiE,CAClE,CAAC;AAiCF;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,SAAS;IAMpB,YACE,IAAmD,EACnC,MAAgC;QAAhC,WAAM,GAAN,MAAM,CAA0B;QAPlD;;WAEG;QACa,QAAG,GAAW,MAAM,EAAE,CAAC;QAMrC,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,C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G,aAAa,CAAC,kBAAkB,CAAC,KAAK,CAA2B,CAAC;IACpF,MAAM,QAAQ,GAAG,IAAI,GAAG,EAA+B,CAAC;IAExD,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QACvB,MAAM,OAAO,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;QACjD,MAAM,qBAAqB,GAAG,WAAW,CAAC,CAAC,YAAY,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QACnE,IAAI,qBAAqB,CAAC,MAAM,KAAK,gBAAgB,CAAC,KAAK,EAAE,CAAC;YAC5D,MAAM,aAAa,CAAC,QAAQ,CAC1B,IAAI,eAAe,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,aAAa,CAAC,QAAQ,CAC1B,IAAI,6BAA6B,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"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { InputTargetPrincipal } from '../agent/api.ts';
|
|
2
|
+
import type { TargetPrincipal } from '../certificate.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Converts InputTargetPrincipal to TargetPrincipal via Principal.from
|
|
5
|
+
* @param target
|
|
6
|
+
* @returns TargetPrincipal
|
|
7
|
+
*/
|
|
8
|
+
export declare function inputToTarget(target: InputTargetPrincipal): TargetPrincipal;
|
|
9
|
+
/**
|
|
10
|
+
* Stringifies a TargetPrincipal into a unique string key.
|
|
11
|
+
* @param target
|
|
12
|
+
* @returns Key suitable for use in e.g. {@link ExpirableStore}
|
|
13
|
+
*/
|
|
14
|
+
export declare function getTargetKey(target: TargetPrincipal): string;
|
|
15
|
+
//# sourceMappingURL=target.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"target.d.ts","sourceRoot":"","sources":["../../../../src/agent/utils/target.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGzD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,oBAAoB,GAAG,eAAe,CAK3E;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,CAI5D"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Principal } from '../../principal/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Converts InputTargetPrincipal to TargetPrincipal via Principal.from
|
|
4
|
+
* @param target
|
|
5
|
+
* @returns TargetPrincipal
|
|
6
|
+
*/
|
|
7
|
+
export function inputToTarget(target) {
|
|
8
|
+
if ('canisterId' in target) {
|
|
9
|
+
return { canisterId: Principal.from(target.canisterId) };
|
|
10
|
+
}
|
|
11
|
+
return { subnetId: Principal.from(target.subnetId) };
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Stringifies a TargetPrincipal into a unique string key.
|
|
15
|
+
* @param target
|
|
16
|
+
* @returns Key suitable for use in e.g. {@link ExpirableStore}
|
|
17
|
+
*/
|
|
18
|
+
export function getTargetKey(target) {
|
|
19
|
+
return 'canisterId' in target
|
|
20
|
+
? `canister:${target.canisterId.toText()}`
|
|
21
|
+
: `subnet:${target.subnetId.toText()}`;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=target.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"target.js","sourceRoot":"","sources":["../../../../src/agent/utils/target.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAKvC;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,MAA4B;IACxD,IAAI,YAAY,IAAI,MAAM,EAAE,CAAC;QAC3B,OAAO,EAAE,UAAU,EAAE,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;IAC3D,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;AACvD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,MAAuB;IAClD,OAAO,YAAY,IAAI,MAAM;QAC3B,CAAC,CAAC,YAAY,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE;QAC1C,CAAC,CAAC,UAAU,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC;AAC3C,CAAC"}
|
|
@@ -62,7 +62,8 @@ export declare class PipeArrayBuffer {
|
|
|
62
62
|
*/
|
|
63
63
|
export declare function uint8FromBufLike(bufLike: ArrayBuffer | Uint8Array | DataView | ArrayBufferView | ArrayBufferLike | [number] | number[] | {
|
|
64
64
|
buffer: ArrayBuffer;
|
|
65
|
-
}):
|
|
65
|
+
}): Uint8ArrayBuffer;
|
|
66
|
+
export type Uint8ArrayBuffer = ReturnType<typeof Uint8Array.of>;
|
|
66
67
|
/**
|
|
67
68
|
*
|
|
68
69
|
* @param u1 uint8Array 1
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buffer.d.ts","sourceRoot":"","sources":["../../../../src/candid/utils/buffer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,MAAM,CAAC,GAAG,WAAW,EAAE,UAAU,EAAE,GAAG,UAAU,CAQ/D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C,EAAE,UAAU,EAAE,MAAM,SAA0B;IAkBjE,IAAI,MAAM,IAAI,UAAU,CAGvB;IAED,IAAI,UAAU,IAAI,MAAM,CAEvB;IAED;;;OAGG;IACI,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU;IAM7B,SAAS,IAAI,MAAM,GAAG,SAAS;IAStC;;;OAGG;IACI,KAAK,CAAC,GAAG,EAAE,UAAU,GAAG,IAAI;IAoBnC;;OAEG;IACH,IAAW,GAAG,IAAI,OAAO,CAExB;IAED;;;OAGG;IACI,KAAK,CAAC,MAAM,EAAE,MAAM;CAW5B;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EACH,WAAW,GACX,UAAU,GACV,QAAQ,GACR,eAAe,GACf,eAAe,GACf,CAAC,MAAM,CAAC,GACR,MAAM,EAAE,GACR;IAAE,MAAM,EAAE,WAAW,CAAA;CAAE,GAC1B,gBAAgB,CAqBlB;AACD,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC,OAAO,UAAU,CAAC,EAAE,CAAC,CAAC;AAEhE;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,UAAU,GAAG,MAAM,CAU9D;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,UAAU,GAAG,OAAO,CAEnE;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,UAAU,GAAG,QAAQ,CAK3D"}
|
|
@@ -129,7 +129,10 @@ export function uint8FromBufLike(bufLike) {
|
|
|
129
129
|
throw new Error('Input cannot be null or undefined');
|
|
130
130
|
}
|
|
131
131
|
if (bufLike instanceof Uint8Array) {
|
|
132
|
-
|
|
132
|
+
if (bufLike.buffer instanceof ArrayBuffer) {
|
|
133
|
+
return bufLike;
|
|
134
|
+
}
|
|
135
|
+
return new Uint8Array(bufLike);
|
|
133
136
|
}
|
|
134
137
|
if (bufLike instanceof ArrayBuffer) {
|
|
135
138
|
return new Uint8Array(bufLike);
|
|
@@ -140,7 +143,7 @@ export function uint8FromBufLike(bufLike) {
|
|
|
140
143
|
if ('buffer' in bufLike) {
|
|
141
144
|
return uint8FromBufLike(bufLike.buffer);
|
|
142
145
|
}
|
|
143
|
-
return new Uint8Array(bufLike);
|
|
146
|
+
return new Uint8Array(bufLike).slice();
|
|
144
147
|
}
|
|
145
148
|
/**
|
|
146
149
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buffer.js","sourceRoot":"","sources":["../../../../src/candid/utils/buffer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,MAAM,CAAC,GAAG,WAAyB;IACjD,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE,CAAC,GAAG,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC;IAC3F,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,MAAM,CAAC,IAAI,WAAW,EAAE,CAAC;QAC5B,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;QACrB,KAAK,IAAI,CAAC,CAAC,UAAU,CAAC;IACxB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,MAAM,OAAO,eAAe;IAO1B;;OAEG;IACI,IAAI;QACT,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED;;;OAGG;IACI,OAAO,CAAC,UAAsB;QACnC,IAAI,CAAC,CAAC,UAAU,YAAY,UAAU,CAAC,EAAE,CAAC;YACxC,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;QACrD,CAAC;QACD,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC;IAC1B,CAAC;IAQD;;;;OAIG;IACH,YAAY,MAAmB,EAAE,MAAM,GAAG,M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CAAC,KAAiB;IAC/C,IAAI,CAAC,CAAC,KAAK,YAAY,UAAU,CAAC,EAAE,CAAC;QACnC,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IAChD,CAAC;IACD,OAAO,IAAI,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;AACxE,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ToCborValue } from '../../agent/index.js';
|
|
2
2
|
import { type DerEncodedPublicKey, type HttpAgentRequest, type PublicKey, type Signature, SignIdentity } from '../../agent/index.js';
|
|
3
|
+
import type { Uint8ArrayBuffer } from '../../candid/index.js';
|
|
3
4
|
import { Principal } from '../../principal/index.js';
|
|
4
5
|
import { PartialIdentity } from './partial.ts';
|
|
5
6
|
/**
|
|
@@ -9,13 +10,15 @@ import { PartialIdentity } from './partial.ts';
|
|
|
9
10
|
* {@link DelegationChain}
|
|
10
11
|
*/
|
|
11
12
|
export declare class Delegation implements ToCborValue {
|
|
12
|
-
readonly pubkey: Uint8Array;
|
|
13
13
|
readonly expiration: bigint;
|
|
14
14
|
readonly targets?: Principal[] | undefined;
|
|
15
|
-
|
|
15
|
+
readonly permissions?: string | undefined;
|
|
16
|
+
readonly pubkey: Uint8ArrayBuffer;
|
|
17
|
+
constructor(pubkey: Uint8Array, expiration: bigint, targets?: Principal[] | undefined, permissions?: string | undefined);
|
|
16
18
|
toCborValue(): {
|
|
19
|
+
permissions?: string | undefined;
|
|
17
20
|
targets?: Principal[] | undefined;
|
|
18
|
-
pubkey: Uint8Array<
|
|
21
|
+
pubkey: Uint8Array<ArrayBuffer>;
|
|
19
22
|
expiration: bigint;
|
|
20
23
|
};
|
|
21
24
|
toJSON(): JsonnableDelegation;
|
|
@@ -30,6 +33,7 @@ interface JsonnableDelegation {
|
|
|
30
33
|
expiration: string;
|
|
31
34
|
pubkey: string;
|
|
32
35
|
targets?: string[];
|
|
36
|
+
permissions?: string;
|
|
33
37
|
}
|
|
34
38
|
/**
|
|
35
39
|
* A signed delegation, which lends its identity to the public key in the delegation
|
|
@@ -49,6 +53,7 @@ export interface JsonnableDelegationChain {
|
|
|
49
53
|
pubkey: string;
|
|
50
54
|
expiration: string;
|
|
51
55
|
targets?: string[];
|
|
56
|
+
permissions?: string;
|
|
52
57
|
};
|
|
53
58
|
}>;
|
|
54
59
|
}
|
|
@@ -88,10 +93,12 @@ export declare class DelegationChain {
|
|
|
88
93
|
* @param options A set of options for this delegation. expiration and previous
|
|
89
94
|
* @param options.previous - Another DelegationChain that this chain should start with.
|
|
90
95
|
* @param options.targets - targets that scope the delegation (e.g. Canister Principals)
|
|
96
|
+
* @param options.permissions - restricts the kinds of calls the delegation permits (e.g. "queries")
|
|
91
97
|
*/
|
|
92
98
|
static create(from: SignIdentity, to: PublicKey, expiration?: Date, options?: {
|
|
93
99
|
previous?: DelegationChain;
|
|
94
100
|
targets?: Principal[];
|
|
101
|
+
permissions?: string;
|
|
95
102
|
}): Promise<DelegationChain>;
|
|
96
103
|
/**
|
|
97
104
|
* Creates a DelegationChain object from a JSON string.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delegation.d.ts","sourceRoot":"","sources":["../../../../src/identity/identity/delegation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EACL,KAAK,mBAAmB,EACxB,KAAK,gBAAgB,EACrB,KAAK,SAAS,EAEd,KAAK,SAAS,EACd,YAAY,EAGb,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAuB/C;;;;;GAKG;AACH,qBAAa,UAAW,YAAW,WAAW;
|
|
1
|
+
{"version":3,"file":"delegation.d.ts","sourceRoot":"","sources":["../../../../src/identity/identity/delegation.ts"],"names":[],"mappings":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,OAAO,CAAC;CAe3E;AAED;;GAEG;AACH,qBAAa,yBAA0B,SAAQ,eAAe;;IAG5D;;OAEG;IACH,IAAI,UAAU,IAAI,eAAe,CAEhC;IAED,OAAO;IAKP;;;;OAIG;WACW,cAAc,CAAC,GAAG,EAAE,SAAS,EAAE,UAAU,EAAE,eAAe;CAGzE;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,KAAK,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,KAAK,CAAC,SAAS,GAAG,MAAM,CAAC,CAAC;CACxD;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,eAAe,EAAE,MAAM,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAyCjG"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { requestIdOf, SignIdentity, IC_REQUEST_DOMAIN_SEPARATOR, IC_REQUEST_AUTH_DELEGATION_DOMAIN_SEPARATOR, } from '../../agent/index.js';
|
|
2
2
|
import { Principal } from '../../principal/index.js';
|
|
3
3
|
import { PartialIdentity } from "./partial.js";
|
|
4
|
-
import { bytesToHex, hexToBytes } from '@noble/hashes/utils';
|
|
4
|
+
import { bytesToHex, hexToBytes } from '@noble/hashes/utils.js';
|
|
5
5
|
/**
|
|
6
6
|
* Safe wrapper around bytesToHex that handles ArrayBuffer/Uint8Array type conversion.
|
|
7
7
|
* Required because `@noble/hashes` v1.8+ strictly expects Uint8Array inputs.
|
|
@@ -26,10 +26,11 @@ function _parseBlob(value) {
|
|
|
26
26
|
* {@link DelegationChain}
|
|
27
27
|
*/
|
|
28
28
|
export class Delegation {
|
|
29
|
-
constructor(pubkey, expiration, targets) {
|
|
30
|
-
this.pubkey = pubkey;
|
|
29
|
+
constructor(pubkey, expiration, targets, permissions) {
|
|
31
30
|
this.expiration = expiration;
|
|
32
31
|
this.targets = targets;
|
|
32
|
+
this.permissions = permissions;
|
|
33
|
+
this.pubkey = pubkey.slice();
|
|
33
34
|
}
|
|
34
35
|
toCborValue() {
|
|
35
36
|
return {
|
|
@@ -38,16 +39,22 @@ export class Delegation {
|
|
|
38
39
|
...(this.targets && {
|
|
39
40
|
targets: this.targets,
|
|
40
41
|
}),
|
|
42
|
+
...(this.permissions && {
|
|
43
|
+
permissions: this.permissions,
|
|
44
|
+
}),
|
|
41
45
|
};
|
|
42
46
|
}
|
|
43
47
|
toJSON() {
|
|
44
48
|
// every string should be hex and once-de-hexed,
|
|
45
49
|
// discoverable what it is (e.g. de-hex to get JSON with a 'type' property, or de-hex to DER
|
|
46
50
|
// with an OID). After de-hex, if it's not obvious what it is, it's an ArrayBuffer.
|
|
51
|
+
// `permissions` is the exception: it is a semantic value (e.g. "queries"),
|
|
52
|
+
// not opaque binary, so it is kept as a plain string rather than hex-encoded.
|
|
47
53
|
return {
|
|
48
54
|
expiration: this.expiration.toString(16),
|
|
49
55
|
pubkey: safeBytesToHex(this.pubkey),
|
|
50
56
|
...(this.targets && { targets: this.targets.map(p => p.toHex()) }),
|
|
57
|
+
...(this.permissions && { permissions: this.permissions }),
|
|
51
58
|
};
|
|
52
59
|
}
|
|
53
60
|
}
|
|
@@ -57,10 +64,11 @@ export class Delegation {
|
|
|
57
64
|
* @param to The identity that receives the delegation.
|
|
58
65
|
* @param expiration An expiration date for this delegation.
|
|
59
66
|
* @param targets Limit this delegation to the target principals.
|
|
67
|
+
* @param permissions Restrict the kinds of calls the delegation permits (e.g. "queries").
|
|
60
68
|
*/
|
|
61
|
-
async function _createSingleDelegation(from, to, expiration, targets) {
|
|
69
|
+
async function _createSingleDelegation(from, to, expiration, targets, permissions) {
|
|
62
70
|
const delegation = new Delegation(to.toDer(), BigInt(+expiration) * BigInt(1000000), // In nanoseconds.
|
|
63
|
-
targets);
|
|
71
|
+
targets, permissions);
|
|
64
72
|
// The signature is calculated by signing the concatenation of the domain separator
|
|
65
73
|
// and the message.
|
|
66
74
|
// Note: To ensure Safari treats this as a user gesture, ensure to not use async methods
|
|
@@ -110,9 +118,10 @@ export class DelegationChain {
|
|
|
110
118
|
* @param options A set of options for this delegation. expiration and previous
|
|
111
119
|
* @param options.previous - Another DelegationChain that this chain should start with.
|
|
112
120
|
* @param options.targets - targets that scope the delegation (e.g. Canister Principals)
|
|
121
|
+
* @param options.permissions - restricts the kinds of calls the delegation permits (e.g. "queries")
|
|
113
122
|
*/
|
|
114
123
|
static async create(from, to, expiration = new Date(Date.now() + 15 * 60 * 1000), options = {}) {
|
|
115
|
-
const delegation = await _createSingleDelegation(from, to, expiration, options.targets);
|
|
124
|
+
const delegation = await _createSingleDelegation(from, to, expiration, options.targets, options.permissions);
|
|
116
125
|
return new DelegationChain([...(options.previous?.delegations || []), delegation], options.previous?.publicKey || from.getPublicKey().toDer());
|
|
117
126
|
}
|
|
118
127
|
/**
|
|
@@ -126,10 +135,13 @@ export class DelegationChain {
|
|
|
126
135
|
}
|
|
127
136
|
const parsedDelegations = delegations.map(signedDelegation => {
|
|
128
137
|
const { delegation, signature } = signedDelegation;
|
|
129
|
-
const { pubkey, expiration, targets } = delegation;
|
|
138
|
+
const { pubkey, expiration, targets, permissions } = delegation;
|
|
130
139
|
if (targets !== undefined && !Array.isArray(targets)) {
|
|
131
140
|
throw new Error('Invalid targets.');
|
|
132
141
|
}
|
|
142
|
+
if (permissions !== undefined && typeof permissions !== 'string') {
|
|
143
|
+
throw new Error('Invalid permissions.');
|
|
144
|
+
}
|
|
133
145
|
return {
|
|
134
146
|
delegation: new Delegation(_parseBlob(pubkey), BigInt(`0x${expiration}`), // expiration in JSON is an hexa string (See toJSON() below).
|
|
135
147
|
targets &&
|
|
@@ -138,7 +150,7 @@ export class DelegationChain {
|
|
|
138
150
|
throw new Error('Invalid target.');
|
|
139
151
|
}
|
|
140
152
|
return Principal.fromHex(t);
|
|
141
|
-
})),
|
|
153
|
+
}), permissions),
|
|
142
154
|
signature: _parseBlob(signature),
|
|
143
155
|
};
|
|
144
156
|
});
|
|
@@ -160,7 +172,7 @@ export class DelegationChain {
|
|
|
160
172
|
return {
|
|
161
173
|
delegations: this.delegations.map(signedDelegation => {
|
|
162
174
|
const { delegation, signature } = signedDelegation;
|
|
163
|
-
const { targets } = delegation;
|
|
175
|
+
const { targets, permissions } = delegation;
|
|
164
176
|
return {
|
|
165
177
|
delegation: {
|
|
166
178
|
expiration: delegation.expiration.toString(16),
|
|
@@ -168,6 +180,7 @@ export class DelegationChain {
|
|
|
168
180
|
...(targets && {
|
|
169
181
|
targets: targets.map(t => t.toHex()),
|
|
170
182
|
}),
|
|
183
|
+
...(permissions && { permissions }),
|
|
171
184
|
},
|
|
172
185
|
signature: safeBytesToHex(signature),
|
|
173
186
|
};
|