@icp-sdk/core 5.0.0-beta.0 → 5.0.0-beta.2

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 (154) hide show
  1. package/README.md +0 -2
  2. package/lib/cjs/agent/actor.js +2 -2
  3. package/lib/cjs/agent/actor.js.map +1 -1
  4. package/lib/cjs/agent/agent/api.d.ts +6 -6
  5. package/lib/cjs/agent/agent/api.js +4 -4
  6. package/lib/cjs/agent/agent/http/__certificates__/goldenCertificates.d.ts +30 -0
  7. package/lib/cjs/agent/agent/http/__certificates__/goldenCertificates.d.ts.map +1 -1
  8. package/lib/cjs/agent/agent/http/__certificates__/goldenCertificates.js +33 -1
  9. package/lib/cjs/agent/agent/http/__certificates__/goldenCertificates.js.map +1 -1
  10. package/lib/cjs/agent/agent/http/index.d.ts +23 -5
  11. package/lib/cjs/agent/agent/http/index.d.ts.map +1 -1
  12. package/lib/cjs/agent/agent/http/index.js +201 -86
  13. package/lib/cjs/agent/agent/http/index.js.map +1 -1
  14. package/lib/cjs/agent/agent/index.d.ts +2 -0
  15. package/lib/cjs/agent/agent/index.d.ts.map +1 -1
  16. package/lib/cjs/agent/agent/index.js +2 -0
  17. package/lib/cjs/agent/agent/index.js.map +1 -1
  18. package/lib/cjs/agent/canisterStatus/index.d.ts +18 -50
  19. package/lib/cjs/agent/canisterStatus/index.d.ts.map +1 -1
  20. package/lib/cjs/agent/canisterStatus/index.js +30 -97
  21. package/lib/cjs/agent/canisterStatus/index.js.map +1 -1
  22. package/lib/cjs/agent/certificate.d.ts +68 -10
  23. package/lib/cjs/agent/certificate.d.ts.map +1 -1
  24. package/lib/cjs/agent/certificate.js +198 -27
  25. package/lib/cjs/agent/certificate.js.map +1 -1
  26. package/lib/cjs/agent/constants.d.ts +4 -0
  27. package/lib/cjs/agent/constants.d.ts.map +1 -1
  28. package/lib/cjs/agent/constants.js +5 -1
  29. package/lib/cjs/agent/constants.js.map +1 -1
  30. package/lib/cjs/agent/errors.d.ts +9 -2
  31. package/lib/cjs/agent/errors.d.ts.map +1 -1
  32. package/lib/cjs/agent/errors.js +19 -7
  33. package/lib/cjs/agent/errors.js.map +1 -1
  34. package/lib/cjs/agent/index.d.ts +97 -5
  35. package/lib/cjs/agent/index.d.ts.map +1 -1
  36. package/lib/cjs/agent/index.js +92 -11
  37. package/lib/cjs/agent/index.js.map +1 -1
  38. package/lib/cjs/agent/polling/index.js +1 -1
  39. package/lib/cjs/agent/polling/index.js.map +1 -1
  40. package/lib/cjs/agent/subnetStatus/index.d.ts +70 -0
  41. package/lib/cjs/agent/subnetStatus/index.d.ts.map +1 -0
  42. package/lib/cjs/agent/subnetStatus/index.js +219 -0
  43. package/lib/cjs/agent/subnetStatus/index.js.map +1 -0
  44. package/lib/cjs/agent/utils/readState.d.ts +84 -0
  45. package/lib/cjs/agent/utils/readState.d.ts.map +1 -0
  46. package/lib/cjs/agent/utils/readState.js +149 -0
  47. package/lib/cjs/agent/utils/readState.js.map +1 -0
  48. package/lib/cjs/candid/index.d.ts +20 -1
  49. package/lib/cjs/candid/index.d.ts.map +1 -1
  50. package/lib/cjs/candid/index.js +20 -1
  51. package/lib/cjs/candid/index.js.map +1 -1
  52. package/lib/cjs/identity/index.d.ts +30 -7
  53. package/lib/cjs/identity/index.d.ts.map +1 -1
  54. package/lib/cjs/identity/index.js +31 -11
  55. package/lib/cjs/identity/index.js.map +1 -1
  56. package/lib/cjs/identity/secp256k1/index.d.ts +48 -1
  57. package/lib/cjs/identity/secp256k1/index.d.ts.map +1 -1
  58. package/lib/cjs/identity/secp256k1/index.js +48 -1
  59. package/lib/cjs/identity/secp256k1/index.js.map +1 -1
  60. package/lib/cjs/identity/secp256k1/pem.d.ts.map +1 -1
  61. package/lib/cjs/identity/secp256k1/pem.js +1 -2
  62. package/lib/cjs/identity/secp256k1/pem.js.map +1 -1
  63. package/lib/cjs/principal/index.d.ts +15 -0
  64. package/lib/cjs/principal/index.d.ts.map +1 -1
  65. package/lib/cjs/principal/index.js +15 -0
  66. package/lib/cjs/principal/index.js.map +1 -1
  67. package/lib/esm/agent/actor.js +3 -3
  68. package/lib/esm/agent/actor.js.map +1 -1
  69. package/lib/esm/agent/agent/api.d.ts +6 -6
  70. package/lib/esm/agent/agent/api.js +3 -3
  71. package/lib/esm/agent/agent/http/__certificates__/goldenCertificates.d.ts +30 -0
  72. package/lib/esm/agent/agent/http/__certificates__/goldenCertificates.d.ts.map +1 -1
  73. package/lib/esm/agent/agent/http/__certificates__/goldenCertificates.js +33 -1
  74. package/lib/esm/agent/agent/http/__certificates__/goldenCertificates.js.map +1 -1
  75. package/lib/esm/agent/agent/http/index.d.ts +23 -5
  76. package/lib/esm/agent/agent/http/index.d.ts.map +1 -1
  77. package/lib/esm/agent/agent/http/index.js +203 -84
  78. package/lib/esm/agent/agent/http/index.js.map +1 -1
  79. package/lib/esm/agent/agent/index.d.ts +2 -0
  80. package/lib/esm/agent/agent/index.d.ts.map +1 -1
  81. package/lib/esm/agent/agent/index.js +2 -0
  82. package/lib/esm/agent/agent/index.js.map +1 -1
  83. package/lib/esm/agent/canister-env/index.d.ts +2 -1
  84. package/lib/esm/agent/canister-env/index.d.ts.map +1 -1
  85. package/lib/esm/agent/canister-env/index.js +2 -1
  86. package/lib/esm/agent/canister-env/index.js.map +1 -1
  87. package/lib/esm/agent/canisterStatus/index.d.ts +18 -50
  88. package/lib/esm/agent/canisterStatus/index.d.ts.map +1 -1
  89. package/lib/esm/agent/canisterStatus/index.js +31 -98
  90. package/lib/esm/agent/canisterStatus/index.js.map +1 -1
  91. package/lib/esm/agent/certificate.d.ts +68 -10
  92. package/lib/esm/agent/certificate.d.ts.map +1 -1
  93. package/lib/esm/agent/certificate.js +196 -29
  94. package/lib/esm/agent/certificate.js.map +1 -1
  95. package/lib/esm/agent/constants.d.ts +4 -0
  96. package/lib/esm/agent/constants.d.ts.map +1 -1
  97. package/lib/esm/agent/constants.js +4 -0
  98. package/lib/esm/agent/constants.js.map +1 -1
  99. package/lib/esm/agent/errors.d.ts +9 -2
  100. package/lib/esm/agent/errors.d.ts.map +1 -1
  101. package/lib/esm/agent/errors.js +15 -4
  102. package/lib/esm/agent/errors.js.map +1 -1
  103. package/lib/esm/agent/index.d.ts +97 -5
  104. package/lib/esm/agent/index.d.ts.map +1 -1
  105. package/lib/esm/agent/index.js +97 -5
  106. package/lib/esm/agent/index.js.map +1 -1
  107. package/lib/esm/agent/polling/index.js +1 -1
  108. package/lib/esm/agent/polling/index.js.map +1 -1
  109. package/lib/esm/agent/subnetStatus/index.d.ts +70 -0
  110. package/lib/esm/agent/subnetStatus/index.d.ts.map +1 -0
  111. package/lib/esm/agent/subnetStatus/index.js +178 -0
  112. package/lib/esm/agent/subnetStatus/index.js.map +1 -0
  113. package/lib/esm/agent/utils/readState.d.ts +84 -0
  114. package/lib/esm/agent/utils/readState.d.ts.map +1 -0
  115. package/lib/esm/agent/utils/readState.js +107 -0
  116. package/lib/esm/agent/utils/readState.js.map +1 -0
  117. package/lib/esm/candid/index.d.ts +20 -1
  118. package/lib/esm/candid/index.d.ts.map +1 -1
  119. package/lib/esm/candid/index.js +20 -1
  120. package/lib/esm/candid/index.js.map +1 -1
  121. package/lib/esm/identity/index.d.ts +30 -7
  122. package/lib/esm/identity/index.d.ts.map +1 -1
  123. package/lib/esm/identity/index.js +30 -9
  124. package/lib/esm/identity/index.js.map +1 -1
  125. package/lib/esm/identity/secp256k1/index.d.ts +48 -1
  126. package/lib/esm/identity/secp256k1/index.d.ts.map +1 -1
  127. package/lib/esm/identity/secp256k1/index.js +48 -1
  128. package/lib/esm/identity/secp256k1/index.js.map +1 -1
  129. package/lib/esm/identity/secp256k1/pem.d.ts.map +1 -1
  130. package/lib/esm/identity/secp256k1/pem.js +1 -2
  131. package/lib/esm/identity/secp256k1/pem.js.map +1 -1
  132. package/lib/esm/principal/index.d.ts +15 -0
  133. package/lib/esm/principal/index.d.ts.map +1 -1
  134. package/lib/esm/principal/index.js +15 -0
  135. package/lib/esm/principal/index.js.map +1 -1
  136. package/package.json +3 -1
  137. package/src/agent/actor.ts +3 -3
  138. package/src/agent/agent/api.ts +8 -8
  139. package/src/agent/agent/http/index.ts +259 -97
  140. package/src/agent/agent/index.ts +2 -0
  141. package/src/agent/canister-env/index.ts +2 -1
  142. package/src/agent/canisterStatus/index.ts +46 -196
  143. package/src/agent/certificate.ts +271 -52
  144. package/src/agent/constants.ts +5 -0
  145. package/src/agent/errors.ts +19 -5
  146. package/src/agent/index.ts +97 -5
  147. package/src/agent/polling/index.ts +1 -1
  148. package/src/agent/subnetStatus/index.ts +265 -0
  149. package/src/agent/utils/readState.ts +180 -0
  150. package/src/candid/index.ts +20 -1
  151. package/src/identity/index.ts +30 -10
  152. package/src/identity/secp256k1/index.ts +48 -1
  153. package/src/identity/secp256k1/pem.ts +1 -2
  154. package/src/principal/index.ts +16 -0
@@ -0,0 +1,178 @@
1
+ import { Principal } from '../../principal/index.js';
2
+ import { CertificateVerificationErrorCode, MissingRootKeyErrorCode, ExternalError, AgentError, UnknownError, UnexpectedErrorCode, CertificateTimeErrorCode, ProtocolError, LookupErrorCode, } from "../errors.js";
3
+ import { Certificate, lookupResultToBuffer, decodeCanisterRanges, lookup_path, LookupPathStatus, } from "../certificate.js";
4
+ import * as cbor from "../cbor.js";
5
+ import { decodeTime } from "../utils/leb.js";
6
+ import { utf8ToBytes } from '@noble/hashes/utils';
7
+ import { decodeValue, isCustomPath, lookupNodeKeysFromCertificate, } from "../utils/readState.js";
8
+ // Re-export shared types and functions
9
+ export { CustomPath, IC_ROOT_SUBNET_ID } from "../utils/readState.js";
10
+ /**
11
+ * Requests information from a subnet's `read_state` endpoint.
12
+ * Can be used to request information about the subnet's time, canister ranges, public key, node keys, and metrics.
13
+ * @param {SubnetStatusOptions} options The configuration for the subnet status request.
14
+ * @see {@link SubnetStatusOptions} for detailed options.
15
+ * @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.
16
+ * @example
17
+ * const status = await subnetStatus.request({
18
+ * subnetId: IC_ROOT_SUBNET_ID,
19
+ * paths: ['time', 'nodeKeys'],
20
+ * agent,
21
+ * });
22
+ *
23
+ * const time = status.get('time');
24
+ * const nodeKeys = status.get('nodeKeys');
25
+ */
26
+ export async function request(options) {
27
+ const { agent, paths, disableCertificateTimeVerification = false } = options;
28
+ const subnetId = Principal.from(options.subnetId);
29
+ const uniquePaths = [...new Set(paths)];
30
+ const status = new Map();
31
+ const promises = uniquePaths.map((path, index) => {
32
+ const encodedPath = encodePath(path, subnetId);
33
+ return (async () => {
34
+ try {
35
+ if (agent.rootKey === null) {
36
+ throw ExternalError.fromCode(new MissingRootKeyErrorCode());
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 },
46
+ disableTimeVerification: disableCertificateTimeVerification,
47
+ agent,
48
+ });
49
+ const lookup = (cert, lookupPath) => {
50
+ if (lookupPath === 'nodeKeys') {
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
+ else {
59
+ return {
60
+ path: lookupPath,
61
+ data: lookupResultToBuffer(cert.lookup_path(encodedPath)),
62
+ };
63
+ }
64
+ };
65
+ const { path, data } = lookup(certificate, uniquePaths[index]);
66
+ if (!data) {
67
+ if (typeof path === 'string') {
68
+ status.set(path, null);
69
+ }
70
+ else {
71
+ status.set(path.key, null);
72
+ }
73
+ }
74
+ else {
75
+ switch (path) {
76
+ case 'time': {
77
+ status.set(path, decodeTime(data));
78
+ break;
79
+ }
80
+ case 'canisterRanges': {
81
+ status.set(path, decodeCanisterRanges(data));
82
+ break;
83
+ }
84
+ case 'publicKey': {
85
+ status.set(path, data);
86
+ break;
87
+ }
88
+ case 'nodeKeys': {
89
+ status.set(path, data);
90
+ break;
91
+ }
92
+ default: {
93
+ // Check for CustomPath signature
94
+ if (isCustomPath(path)) {
95
+ status.set(path.key, decodeValue(data, path.decodeStrategy));
96
+ }
97
+ }
98
+ }
99
+ }
100
+ }
101
+ catch (error) {
102
+ // Throw on certificate errors
103
+ if (error instanceof AgentError &&
104
+ (error.hasCode(CertificateVerificationErrorCode) ||
105
+ error.hasCode(CertificateTimeErrorCode))) {
106
+ throw error;
107
+ }
108
+ if (isCustomPath(path)) {
109
+ status.set(path.key, null);
110
+ }
111
+ else {
112
+ status.set(path, null);
113
+ }
114
+ }
115
+ })();
116
+ });
117
+ // Fetch all values separately, as each option can fail
118
+ await Promise.all(promises);
119
+ return status;
120
+ }
121
+ /**
122
+ * Fetch subnet info including node keys from a certificate
123
+ * @param certificate the certificate bytes
124
+ * @param subnetId the subnet ID
125
+ * @returns SubnetStatus with subnet ID and node keys
126
+ */
127
+ export function lookupSubnetInfo(certificate, subnetId) {
128
+ const cert = cbor.decode(certificate);
129
+ const nodeKeys = lookupNodeKeysFromCertificate(cert, subnetId);
130
+ const publicKey = lookupSubnetPublicKey(cert, subnetId);
131
+ return {
132
+ subnetId: subnetId.toText(),
133
+ nodeKeys,
134
+ publicKey,
135
+ };
136
+ }
137
+ function lookupSubnetPublicKey(certificate, subnetId) {
138
+ const subnetLookupResult = lookup_path(['subnet', subnetId.toUint8Array(), 'public_key'], certificate.tree);
139
+ if (subnetLookupResult.status !== LookupPathStatus.Found) {
140
+ throw ProtocolError.fromCode(new LookupErrorCode('Public key not found', subnetLookupResult.status));
141
+ }
142
+ return subnetLookupResult.value;
143
+ }
144
+ /**
145
+ * Encode a path for subnet state queries
146
+ * @param path the path to encode
147
+ * @param subnetId the subnet ID
148
+ * @returns the encoded path as an array of Uint8Arrays
149
+ */
150
+ export function encodePath(path, subnetId) {
151
+ const subnetUint8Array = subnetId.toUint8Array();
152
+ switch (path) {
153
+ case 'time':
154
+ return [utf8ToBytes('time')];
155
+ case 'canisterRanges':
156
+ return [utf8ToBytes('canister_ranges'), subnetUint8Array];
157
+ case 'publicKey':
158
+ return [utf8ToBytes('subnet'), subnetUint8Array, utf8ToBytes('public_key')];
159
+ case 'nodeKeys':
160
+ return [utf8ToBytes('subnet'), subnetUint8Array, utf8ToBytes('node')];
161
+ default: {
162
+ // Check for CustomPath signature
163
+ if (isCustomPath(path)) {
164
+ if (typeof path['path'] === 'string' || path['path'] instanceof Uint8Array) {
165
+ // For string paths, treat as a subnet path segment
166
+ const encoded = typeof path['path'] === 'string' ? utf8ToBytes(path['path']) : path['path'];
167
+ return [utf8ToBytes('subnet'), subnetUint8Array, encoded];
168
+ }
169
+ else {
170
+ // For non-simple paths, return the provided custom path
171
+ return path['path'];
172
+ }
173
+ }
174
+ }
175
+ }
176
+ throw UnknownError.fromCode(new UnexpectedErrorCode(`Error while encoding your path for subnet status. Please ensure that your path ${path} was formatted correctly.`));
177
+ }
178
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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,uBAAuB,EACvB,aAAa,EACb,UAAU,EACV,YAAY,EACZ,mBAAmB,EACnB,wBAAwB,EACxB,aAAa,EACb,eAAe,GAChB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAGL,WAAW,EACX,oBAAoB,EACpB,oBAAoB,EACpB,WAAW,EACX,gBAAgB,GACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAKL,WAAW,EACX,YAAY,EACZ,6BAA6B,GAE9B,MAAM,uBAAuB,CAAC;AAE/B,uCAA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AAE,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;qBAAM,CAAC;oBACN,wDAAwD;oBACxD,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC;gBACtB,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IACD,MAAM,YAAY,CAAC,QAAQ,CACzB,IAAI,mBAAmB,CACrB,kFAAkF,IAAI,2BAA2B,CAClH,CACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,84 @@
1
+ import { Principal } from '../../principal/index.js';
2
+ import { type DerEncodedPublicKey } from '../auth.ts';
3
+ import { type Cert } from '../certificate.ts';
4
+ /**
5
+ * The root subnet ID for IC mainnet
6
+ */
7
+ export declare const IC_ROOT_SUBNET_ID: Principal;
8
+ export type SubnetNodeKeys = Map<string, DerEncodedPublicKey>;
9
+ /**
10
+ * Represents the useful information about a subnet
11
+ */
12
+ export type BaseSubnetStatus = {
13
+ /**
14
+ * The subnet ID
15
+ */
16
+ subnetId: string;
17
+ /**
18
+ * The node keys of the subnet
19
+ */
20
+ nodeKeys: SubnetNodeKeys;
21
+ /**
22
+ * Not supported
23
+ */
24
+ metrics?: never;
25
+ };
26
+ /**
27
+ * Base types of an entry on the status map.
28
+ * An entry of null indicates that the request failed, due to lack of permissions or the result being missing.
29
+ */
30
+ export type BaseStatus = string | Uint8Array | Date | Uint8Array[] | Principal[] | bigint | null;
31
+ /**
32
+ * Decode strategy for custom paths
33
+ */
34
+ export type DecodeStrategy = 'cbor' | 'hex' | 'leb128' | 'utf-8' | 'raw';
35
+ /**
36
+ * Interface to define a custom path. Nested paths will be represented as individual buffers, and can be created from text using TextEncoder.
37
+ * @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
40
+ */
41
+ export declare class CustomPath implements CustomPath {
42
+ key: string;
43
+ path: Uint8Array[] | string;
44
+ decodeStrategy: DecodeStrategy;
45
+ constructor(key: string, path: Uint8Array[] | string, decodeStrategy: DecodeStrategy);
46
+ }
47
+ /**
48
+ * Decode a value based on the specified strategy
49
+ * @param data the raw data to decode
50
+ * @param strategy the decode strategy to use
51
+ * @returns the decoded value
52
+ */
53
+ export declare function decodeValue(data: Uint8Array, strategy: DecodeStrategy): BaseStatus;
54
+ /**
55
+ * Decode controllers from CBOR-encoded buffer
56
+ * @param buf the CBOR-encoded buffer to decode
57
+ * @returns an array of principal IDs
58
+ */
59
+ 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
+ /**
68
+ * Check if a path object has custom path signature (has 'key' and 'path' properties)
69
+ * @param path the path to check
70
+ * @returns true if the path has custom path signature, false otherwise
71
+ */
72
+ export declare function isCustomPath<T>(path: T): path is T & {
73
+ key: string;
74
+ path: unknown;
75
+ };
76
+ /**
77
+ * Lookup node keys from a certificate for a given subnet
78
+ * This can be used for both canister and subnet status queries
79
+ * @param certificate the certificate to fetch node keys from
80
+ * @param subnetId the subnet ID to fetch node keys for
81
+ * @returns a map of node IDs to public keys
82
+ */
83
+ export declare function lookupNodeKeysFromCertificate(certificate: Cert, subnetId: Principal): SubnetNodeKeys;
84
+ //# sourceMappingURL=readState.d.ts.map
@@ -0,0 +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,EAAE,KAAK,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EACL,KAAK,IAAI,EAOV,MAAM,mBAAmB,CAAC;AAS3B;;GAEG;AACH,eAAO,MAAM,iBAAiB,WAE7B,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;AAE9D;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,QAAQ,EAAE,cAAc,CAAC;IACzB;;OAEG;IACH,OAAO,CAAC,EAAE,KAAK,CAAC;CACjB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,UAAU,GAAG,IAAI,GAAG,UAAU,EAAE,GAAG,SAAS,EAAE,GAAG,MAAM,GAAG,IAAI,CAAC;AAEjG;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,GAAG,KAAK,CAAC;AAEzE;;;;;GAKG;AACH,qBAAa,UAAW,YAAW,UAAU;IACpC,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;IAC5B,cAAc,EAAE,cAAc,CAAC;gBAC1B,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,GAAG,MAAM,EAAE,cAAc,EAAE,cAAc;CAKrF;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,cAAc,GAAG,UAAU,CAalF;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,UAAU,GAAG,SAAS,EAAE,CAK9D;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,GAAG,UAAU,EAC7B,kBAAkB,EAAE,UAAU,GAC7B,UAAU,EAAE,CAGd;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"}
@@ -0,0 +1,107 @@
1
+ import { Principal } from '../../principal/index.js';
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";
6
+ import { LookupErrorCode, DerKeyLengthMismatchErrorCode, ProtocolError, UnknownError, HashTreeDecodeErrorCode, } from "../errors.js";
7
+ /**
8
+ * The root subnet ID for IC mainnet
9
+ */
10
+ export const IC_ROOT_SUBNET_ID = Principal.fromText('tdb26-jop6k-aogll-7ltgs-eruif-6kk7m-qpktf-gdiqx-mxtrf-vb5e6-eqe');
11
+ /**
12
+ * Interface to define a custom path. Nested paths will be represented as individual buffers, and can be created from text using TextEncoder.
13
+ * @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, represented as an array of buffers
15
+ * @param {string} decodeStrategy the strategy to use to decode the returned value
16
+ */
17
+ export class CustomPath {
18
+ constructor(key, path, decodeStrategy) {
19
+ this.key = key;
20
+ this.path = path;
21
+ this.decodeStrategy = decodeStrategy;
22
+ }
23
+ }
24
+ /**
25
+ * Decode a value based on the specified strategy
26
+ * @param data the raw data to decode
27
+ * @param strategy the decode strategy to use
28
+ * @returns the decoded value
29
+ */
30
+ export function decodeValue(data, strategy) {
31
+ switch (strategy) {
32
+ case 'raw':
33
+ return data;
34
+ case 'leb128':
35
+ return decodeLeb128(data);
36
+ case 'cbor':
37
+ return cbor.decode(data);
38
+ case 'hex':
39
+ return bytesToHex(data);
40
+ case 'utf-8':
41
+ return new TextDecoder().decode(data);
42
+ }
43
+ }
44
+ /**
45
+ * Decode controllers from CBOR-encoded buffer
46
+ * @param buf the CBOR-encoded buffer to decode
47
+ * @returns an array of principal IDs
48
+ */
49
+ export function decodeControllers(buf) {
50
+ const controllersRaw = cbor.decode(buf);
51
+ return controllersRaw.map(buf => {
52
+ return Principal.fromUint8Array(buf);
53
+ });
54
+ }
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
+ /**
66
+ * Check if a path object has custom path signature (has 'key' and 'path' properties)
67
+ * @param path the path to check
68
+ * @returns true if the path has custom path signature, false otherwise
69
+ */
70
+ export function isCustomPath(path) {
71
+ return typeof path === 'object' && path !== null && 'key' in path && 'path' in path;
72
+ }
73
+ /**
74
+ * Lookup node keys from a certificate for a given subnet
75
+ * This can be used for both canister and subnet status queries
76
+ * @param certificate the certificate to fetch node keys from
77
+ * @param subnetId the subnet ID to fetch node keys for
78
+ * @returns a map of node IDs to public keys
79
+ */
80
+ export function lookupNodeKeysFromCertificate(certificate, subnetId) {
81
+ const subnetLookupResult = lookup_subtree(['subnet', subnetId.toUint8Array(), 'node'], certificate.tree);
82
+ if (subnetLookupResult.status !== LookupSubtreeStatus.Found) {
83
+ throw ProtocolError.fromCode(new LookupErrorCode('Node not found', subnetLookupResult.status));
84
+ }
85
+ if (subnetLookupResult.value instanceof Uint8Array) {
86
+ throw UnknownError.fromCode(new HashTreeDecodeErrorCode('Invalid node tree'));
87
+ }
88
+ // The forks are all labeled trees with the <node_id> label
89
+ const nodeForks = flatten_forks(subnetLookupResult.value);
90
+ const nodeKeys = new Map();
91
+ nodeForks.forEach(fork => {
92
+ const node_id = Principal.from(fork[1]).toText();
93
+ const publicKeyLookupResult = lookup_path(['public_key'], fork[2]);
94
+ if (publicKeyLookupResult.status !== LookupPathStatus.Found) {
95
+ throw ProtocolError.fromCode(new LookupErrorCode('Public key not found', publicKeyLookupResult.status));
96
+ }
97
+ const derEncodedPublicKey = publicKeyLookupResult.value;
98
+ if (derEncodedPublicKey.byteLength !== 44) {
99
+ throw ProtocolError.fromCode(new DerKeyLengthMismatchErrorCode(44, derEncodedPublicKey.byteLength));
100
+ }
101
+ else {
102
+ nodeKeys.set(node_id, derEncodedPublicKey);
103
+ }
104
+ });
105
+ return nodeKeys;
106
+ }
107
+ //# sourceMappingURL=readState.js.map
@@ -0,0 +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;AAC/C,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAE9D,OAAO,EAEL,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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C,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"}
@@ -1,5 +1,24 @@
1
1
  /**
2
- * @module api
2
+ * JavaScript and TypeScript module to work with Candid interfaces
3
+ *
4
+ * ## Usage
5
+ *
6
+ * ```ts
7
+ * import { IDL } from '@icp-sdk/core/candid';
8
+ *
9
+ * const MyType = IDL.Record({
10
+ * name: IDL.Text,
11
+ * age: IDL.Nat8,
12
+ * });
13
+ *
14
+ * const encoded = IDL.encode([MyType], [{ name: 'John', age: 30 }]);
15
+ * const decoded = IDL.decode([MyType], encoded);
16
+ *
17
+ * console.log(decoded); // [{ name: 'John', age: 30 }]
18
+ * ```
19
+ *
20
+ * <!-- split here -->
21
+ * @module libs/candid/api
3
22
  */
4
23
  export * from './candid-ui.ts';
5
24
  export * from './candid-core.ts';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/candid/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,uBAAuB,GAC7B,MAAM,UAAU,CAAC;AAClB,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/candid/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAChC,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,uBAAuB,GAC7B,MAAM,UAAU,CAAC;AAClB,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC"}
@@ -1,5 +1,24 @@
1
1
  /**
2
- * @module api
2
+ * JavaScript and TypeScript module to work with Candid interfaces
3
+ *
4
+ * ## Usage
5
+ *
6
+ * ```ts
7
+ * import { IDL } from '@icp-sdk/core/candid';
8
+ *
9
+ * const MyType = IDL.Record({
10
+ * name: IDL.Text,
11
+ * age: IDL.Nat8,
12
+ * });
13
+ *
14
+ * const encoded = IDL.encode([MyType], [{ name: 'John', age: 30 }]);
15
+ * const decoded = IDL.decode([MyType], encoded);
16
+ *
17
+ * console.log(decoded); // [{ name: 'John', age: 30 }]
18
+ * ```
19
+ *
20
+ * <!-- split here -->
21
+ * @module libs/candid/api
3
22
  */
4
23
  export * from "./candid-ui.js";
5
24
  export * from "./candid-core.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/candid/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAMhC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/candid/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAMhC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC"}
@@ -1,5 +1,34 @@
1
1
  /**
2
- * @module api
2
+ * JavaScript and TypeScript module to manage Identities and enable simple Web Authentication flows for applications on the [Internet Computer](https://internetcomputer.org/)
3
+ *
4
+ * ## Usage
5
+ *
6
+ * ```ts
7
+ * import { ECDSAKeyIdentity, Ed25519KeyIdentity, WebAuthnIdentity } from '@icp-sdk/core/identity';
8
+ *
9
+ * const ecdsaIdentity = await ECDSAKeyIdentity.generate();
10
+ * const ed25519Identity = Ed25519KeyIdentity.generate();
11
+ * const webAuthnIdentity = await WebAuthnIdentity.create();
12
+ * ```
13
+ *
14
+ * ### DelegationIdentity
15
+ *
16
+ * The `DelegationIdentity` is typically generated using the [`@icp-sdk/auth`](https://js.icp.build/auth/latest/) package.
17
+ *
18
+ * ### PartialIdentity
19
+ *
20
+ * The `PartialIdentity` is not typically used directly, but is used by the `DelegationIdentity` and `WebAuthnIdentity` classes.
21
+ *
22
+ * ### Secp256k1KeyIdentity
23
+ *
24
+ * See [@icp-sdk/core/identity/secp256k1](https://js.icp.build/core/latest/libs/identity-secp256k1/api/) for more information.
25
+ *
26
+ * ## In Node.js
27
+ *
28
+ * Depending on your version, you may need to use a polyfill and set `global.crypto` in a setup file. If you prefer, you can also pass in a `subtleCrypto` implementation in methods that call for it, either as a direct argument, or in a `cryptoOptions` object.
29
+ *
30
+ * <!-- split here -->
31
+ * @module libs/identity/api
3
32
  */
4
33
  export * from './identity/ed25519.ts';
5
34
  export * from './identity/ecdsa.ts';
@@ -7,10 +36,4 @@ export * from './identity/delegation.ts';
7
36
  export * from './identity/partial.ts';
8
37
  export { WebAuthnIdentity } from './identity/webauthn.ts';
9
38
  export { wrapDER, unwrapDER, DER_COSE_OID, ED25519_OID } from '../agent/index.js';
10
- /**
11
- * @deprecated due to size of dependencies. Use `@icp-sdk/identity/secp256k1` instead.
12
- */
13
- export declare class Secp256k1KeyIdentity {
14
- constructor();
15
- }
16
39
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/identity/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAEvE;;GAEG;AACH,qBAAa,oBAAoB;;CAIhC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/identity/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC"}
@@ -1,5 +1,34 @@
1
1
  /**
2
- * @module api
2
+ * JavaScript and TypeScript module to manage Identities and enable simple Web Authentication flows for applications on the [Internet Computer](https://internetcomputer.org/)
3
+ *
4
+ * ## Usage
5
+ *
6
+ * ```ts
7
+ * import { ECDSAKeyIdentity, Ed25519KeyIdentity, WebAuthnIdentity } from '@icp-sdk/core/identity';
8
+ *
9
+ * const ecdsaIdentity = await ECDSAKeyIdentity.generate();
10
+ * const ed25519Identity = Ed25519KeyIdentity.generate();
11
+ * const webAuthnIdentity = await WebAuthnIdentity.create();
12
+ * ```
13
+ *
14
+ * ### DelegationIdentity
15
+ *
16
+ * The `DelegationIdentity` is typically generated using the [`@icp-sdk/auth`](https://js.icp.build/auth/latest/) package.
17
+ *
18
+ * ### PartialIdentity
19
+ *
20
+ * The `PartialIdentity` is not typically used directly, but is used by the `DelegationIdentity` and `WebAuthnIdentity` classes.
21
+ *
22
+ * ### Secp256k1KeyIdentity
23
+ *
24
+ * See [@icp-sdk/core/identity/secp256k1](https://js.icp.build/core/latest/libs/identity-secp256k1/api/) for more information.
25
+ *
26
+ * ## In Node.js
27
+ *
28
+ * Depending on your version, you may need to use a polyfill and set `global.crypto` in a setup file. If you prefer, you can also pass in a `subtleCrypto` implementation in methods that call for it, either as a direct argument, or in a `cryptoOptions` object.
29
+ *
30
+ * <!-- split here -->
31
+ * @module libs/identity/api
3
32
  */
4
33
  export * from "./identity/ed25519.js";
5
34
  export * from "./identity/ecdsa.js";
@@ -7,12 +36,4 @@ export * from "./identity/delegation.js";
7
36
  export * from "./identity/partial.js";
8
37
  export { WebAuthnIdentity } from "./identity/webauthn.js";
9
38
  export { wrapDER, unwrapDER, DER_COSE_OID, ED25519_OID } from '../agent/index.js';
10
- /**
11
- * @deprecated due to size of dependencies. Use `@icp-sdk/identity/secp256k1` instead.
12
- */
13
- export class Secp256k1KeyIdentity {
14
- constructor() {
15
- throw new Error('Secp256k1KeyIdentity is available in @icp-sdk/identity/secp256k1');
16
- }
17
- }
18
39
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/identity/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAEvE;;GAEG;AACH,MAAM,OAAO,oBAAoB;IAC/B;QACE,MAAM,IAAI,KAAK,CAAC,kEAAkE,CAAC,CAAC;IACtF,CAAC;CACF"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/identity/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC"}
@@ -1,5 +1,52 @@
1
1
  /**
2
- * @module api
2
+ * The `@icp-sdk/core/identity/secp256k1` module provides an implementation of the [`SignIdentity`](https://js.icp.build/core/latest/libs/agent/api/classes/signidentity/) interface for the secp256k1 elliptic curve. It allows you to create and manage key pairs for signing and verification of messages.
3
+ *
4
+ * ## Usage
5
+ *
6
+ * Here's an example of how to use the `Secp256k1KeyIdentity` class to generate a new key pair and sign and verify a message:
7
+ *
8
+ * ```ts
9
+ * import { Secp256k1KeyIdentity } from '@icp-sdk/core/identity/secp256k1';
10
+ *
11
+ * // Generate a new key pair
12
+ * const identity = Secp256k1KeyIdentity.generate();
13
+ *
14
+ * // Sign a message
15
+ * const message = 'Hello, world!';
16
+ * const signature = identity.sign(message);
17
+ *
18
+ * // Verify the signature
19
+ * const isValid = identity.verify(message, signature);
20
+ *
21
+ * console.log(`Signature is ${isValid ? 'valid' : 'invalid'}`);
22
+ * ```
23
+ *
24
+ * You can also use a seed to generate deterministic key pairs:
25
+ *
26
+ * ```ts
27
+ * import { Secp256k1KeyIdentity } from '@icp-sdk/core/identity/secp256k1';
28
+ *
29
+ * const seed = Buffer.from('my-secret-seed', 'utf8');
30
+ * const identity = Secp256k1KeyIdentity.generate(seed);
31
+ * ```
32
+ *
33
+ * The Secp256k1KeyIdentity class also provides methods for converting the key pair to and from JSON-serializable objects:
34
+ *
35
+ * ```ts
36
+ * import { Secp256k1KeyIdentity } from '@icp-sdk/core/identity/secp256k1';
37
+ *
38
+ * // Generate a new key pair
39
+ * const identity = Secp256k1KeyIdentity.generate();
40
+ *
41
+ * // Convert the key pair to a JSON-serializable object
42
+ * const json = identity.toJson();
43
+ *
44
+ * // Convert the JSON-serializable object back to a key pair
45
+ * const restoredIdentity = Secp256k1KeyIdentity.fromJson(json);
46
+ * ```
47
+ *
48
+ * <!-- split here -->
49
+ * @module libs/identity/secp256k1/api
3
50
  */
4
51
  export * from './secp256k1.ts';
5
52
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/identity/secp256k1/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/identity/secp256k1/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AAEH,cAAc,gBAAgB,CAAC"}