@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.
Files changed (259) hide show
  1. package/lib/cjs/agent/actor.d.ts +7 -3
  2. package/lib/cjs/agent/actor.d.ts.map +1 -1
  3. package/lib/cjs/agent/actor.js +18 -5
  4. package/lib/cjs/agent/actor.js.map +1 -1
  5. package/lib/cjs/agent/agent/api.d.ts +71 -10
  6. package/lib/cjs/agent/agent/api.d.ts.map +1 -1
  7. package/lib/cjs/agent/agent/api.js +6 -1
  8. package/lib/cjs/agent/agent/api.js.map +1 -1
  9. package/lib/cjs/agent/agent/http/index.d.ts +9 -12
  10. package/lib/cjs/agent/agent/http/index.d.ts.map +1 -1
  11. package/lib/cjs/agent/agent/http/index.js +224 -176
  12. package/lib/cjs/agent/agent/http/index.js.map +1 -1
  13. package/lib/cjs/agent/auth.d.ts +6 -5
  14. package/lib/cjs/agent/auth.d.ts.map +1 -1
  15. package/lib/cjs/agent/auth.js +3 -3
  16. package/lib/cjs/agent/auth.js.map +1 -1
  17. package/lib/cjs/agent/canisterStatus/index.d.ts +2 -3
  18. package/lib/cjs/agent/canisterStatus/index.d.ts.map +1 -1
  19. package/lib/cjs/agent/canisterStatus/index.js +65 -122
  20. package/lib/cjs/agent/canisterStatus/index.js.map +1 -1
  21. package/lib/cjs/agent/cbor.d.ts +2 -1
  22. package/lib/cjs/agent/cbor.d.ts.map +1 -1
  23. package/lib/cjs/agent/cbor.js +4 -1
  24. package/lib/cjs/agent/cbor.js.map +1 -1
  25. package/lib/cjs/agent/certificate.d.ts +6 -5
  26. package/lib/cjs/agent/certificate.d.ts.map +1 -1
  27. package/lib/cjs/agent/certificate.js +14 -18
  28. package/lib/cjs/agent/certificate.js.map +1 -1
  29. package/lib/cjs/agent/der.d.ts +3 -2
  30. package/lib/cjs/agent/der.d.ts.map +1 -1
  31. package/lib/cjs/agent/der.js.map +1 -1
  32. package/lib/cjs/agent/errors.d.ts +7 -1
  33. package/lib/cjs/agent/errors.d.ts.map +1 -1
  34. package/lib/cjs/agent/errors.js +34 -16
  35. package/lib/cjs/agent/errors.js.map +1 -1
  36. package/lib/cjs/agent/polling/index.d.ts +7 -7
  37. package/lib/cjs/agent/polling/index.d.ts.map +1 -1
  38. package/lib/cjs/agent/polling/index.js +19 -20
  39. package/lib/cjs/agent/polling/index.js.map +1 -1
  40. package/lib/cjs/agent/polling/strategy.d.ts.map +1 -1
  41. package/lib/cjs/agent/polling/strategy.js +6 -6
  42. package/lib/cjs/agent/polling/strategy.js.map +1 -1
  43. package/lib/cjs/agent/polling/types.d.ts +3 -4
  44. package/lib/cjs/agent/polling/types.d.ts.map +1 -1
  45. package/lib/cjs/agent/public_key.d.ts +3 -2
  46. package/lib/cjs/agent/public_key.d.ts.map +1 -1
  47. package/lib/cjs/agent/public_key.js +2 -2
  48. package/lib/cjs/agent/public_key.js.map +1 -1
  49. package/lib/cjs/agent/request_id.js +10 -10
  50. package/lib/cjs/agent/request_id.js.map +1 -1
  51. package/lib/cjs/agent/subnetStatus/index.d.ts +3 -2
  52. package/lib/cjs/agent/subnetStatus/index.d.ts.map +1 -1
  53. package/lib/cjs/agent/subnetStatus/index.js +65 -88
  54. package/lib/cjs/agent/subnetStatus/index.js.map +1 -1
  55. package/lib/cjs/agent/utils/bls.d.ts.map +1 -1
  56. package/lib/cjs/agent/utils/bls.js +7 -6
  57. package/lib/cjs/agent/utils/bls.js.map +1 -1
  58. package/lib/cjs/agent/utils/readState.d.ts +104 -15
  59. package/lib/cjs/agent/utils/readState.d.ts.map +1 -1
  60. package/lib/cjs/agent/utils/readState.js +106 -17
  61. package/lib/cjs/agent/utils/readState.js.map +1 -1
  62. package/lib/cjs/agent/utils/target.d.ts +15 -0
  63. package/lib/cjs/agent/utils/target.d.ts.map +1 -0
  64. package/lib/cjs/agent/utils/target.js +27 -0
  65. package/lib/cjs/agent/utils/target.js.map +1 -0
  66. package/lib/cjs/candid/utils/buffer.d.ts +2 -1
  67. package/lib/cjs/candid/utils/buffer.d.ts.map +1 -1
  68. package/lib/cjs/candid/utils/buffer.js +5 -2
  69. package/lib/cjs/candid/utils/buffer.js.map +1 -1
  70. package/lib/cjs/identity/identity/delegation.d.ts +10 -3
  71. package/lib/cjs/identity/identity/delegation.d.ts.map +1 -1
  72. package/lib/cjs/identity/identity/delegation.js +25 -12
  73. package/lib/cjs/identity/identity/delegation.js.map +1 -1
  74. package/lib/cjs/identity/identity/ecdsa.d.ts +2 -2
  75. package/lib/cjs/identity/identity/ecdsa.d.ts.map +1 -1
  76. package/lib/cjs/identity/identity/ecdsa.js +3 -2
  77. package/lib/cjs/identity/identity/ecdsa.js.map +1 -1
  78. package/lib/cjs/identity/identity/ed25519.d.ts +3 -2
  79. package/lib/cjs/identity/identity/ed25519.d.ts.map +1 -1
  80. package/lib/cjs/identity/identity/ed25519.js +18 -15
  81. package/lib/cjs/identity/identity/ed25519.js.map +1 -1
  82. package/lib/cjs/identity/identity/webauthn.d.ts +4 -3
  83. package/lib/cjs/identity/identity/webauthn.d.ts.map +1 -1
  84. package/lib/cjs/identity/identity/webauthn.js +12 -11
  85. package/lib/cjs/identity/identity/webauthn.js.map +1 -1
  86. package/lib/cjs/identity/secp256k1/der.d.ts +2 -1
  87. package/lib/cjs/identity/secp256k1/der.d.ts.map +1 -1
  88. package/lib/cjs/identity/secp256k1/der.js.map +1 -1
  89. package/lib/cjs/identity/secp256k1/pem.d.ts +4 -3
  90. package/lib/cjs/identity/secp256k1/pem.d.ts.map +1 -1
  91. package/lib/cjs/identity/secp256k1/pem.js +2 -2
  92. package/lib/cjs/identity/secp256k1/pem.js.map +1 -1
  93. package/lib/cjs/identity/secp256k1/secp256k1.d.ts +5 -4
  94. package/lib/cjs/identity/secp256k1/secp256k1.d.ts.map +1 -1
  95. package/lib/cjs/identity/secp256k1/secp256k1.js +17 -20
  96. package/lib/cjs/identity/secp256k1/secp256k1.js.map +1 -1
  97. package/lib/cjs/principal/principal.js +5 -5
  98. package/lib/cjs/principal/principal.js.map +1 -1
  99. package/lib/esm/agent/actor.d.ts +7 -3
  100. package/lib/esm/agent/actor.d.ts.map +1 -1
  101. package/lib/esm/agent/actor.js +18 -5
  102. package/lib/esm/agent/actor.js.map +1 -1
  103. package/lib/esm/agent/agent/api.d.ts +71 -10
  104. package/lib/esm/agent/agent/api.d.ts.map +1 -1
  105. package/lib/esm/agent/agent/api.js +1 -0
  106. package/lib/esm/agent/agent/api.js.map +1 -1
  107. package/lib/esm/agent/agent/http/index.d.ts +9 -12
  108. package/lib/esm/agent/agent/http/index.d.ts.map +1 -1
  109. package/lib/esm/agent/agent/http/index.js +218 -170
  110. package/lib/esm/agent/agent/http/index.js.map +1 -1
  111. package/lib/esm/agent/auth.d.ts +6 -5
  112. package/lib/esm/agent/auth.d.ts.map +1 -1
  113. package/lib/esm/agent/auth.js +1 -1
  114. package/lib/esm/agent/auth.js.map +1 -1
  115. package/lib/esm/agent/canister-env/index.js +1 -1
  116. package/lib/esm/agent/canister-env/index.js.map +1 -1
  117. package/lib/esm/agent/canisterStatus/index.d.ts +2 -3
  118. package/lib/esm/agent/canisterStatus/index.d.ts.map +1 -1
  119. package/lib/esm/agent/canisterStatus/index.js +66 -122
  120. package/lib/esm/agent/canisterStatus/index.js.map +1 -1
  121. package/lib/esm/agent/cbor.d.ts +2 -1
  122. package/lib/esm/agent/cbor.d.ts.map +1 -1
  123. package/lib/esm/agent/cbor.js +4 -1
  124. package/lib/esm/agent/cbor.js.map +1 -1
  125. package/lib/esm/agent/certificate.d.ts +6 -5
  126. package/lib/esm/agent/certificate.d.ts.map +1 -1
  127. package/lib/esm/agent/certificate.js +5 -9
  128. package/lib/esm/agent/certificate.js.map +1 -1
  129. package/lib/esm/agent/der.d.ts +3 -2
  130. package/lib/esm/agent/der.d.ts.map +1 -1
  131. package/lib/esm/agent/der.js.map +1 -1
  132. package/lib/esm/agent/errors.d.ts +7 -1
  133. package/lib/esm/agent/errors.d.ts.map +1 -1
  134. package/lib/esm/agent/errors.js +18 -1
  135. package/lib/esm/agent/errors.js.map +1 -1
  136. package/lib/esm/agent/polling/index.d.ts +7 -7
  137. package/lib/esm/agent/polling/index.d.ts.map +1 -1
  138. package/lib/esm/agent/polling/index.js +19 -20
  139. package/lib/esm/agent/polling/index.js.map +1 -1
  140. package/lib/esm/agent/polling/strategy.d.ts.map +1 -1
  141. package/lib/esm/agent/polling/strategy.js +6 -6
  142. package/lib/esm/agent/polling/strategy.js.map +1 -1
  143. package/lib/esm/agent/polling/types.d.ts +3 -4
  144. package/lib/esm/agent/polling/types.d.ts.map +1 -1
  145. package/lib/esm/agent/public_key.d.ts +3 -2
  146. package/lib/esm/agent/public_key.d.ts.map +1 -1
  147. package/lib/esm/agent/public_key.js +2 -2
  148. package/lib/esm/agent/public_key.js.map +1 -1
  149. package/lib/esm/agent/request_id.js +2 -2
  150. package/lib/esm/agent/request_id.js.map +1 -1
  151. package/lib/esm/agent/subnetStatus/index.d.ts +3 -2
  152. package/lib/esm/agent/subnetStatus/index.d.ts.map +1 -1
  153. package/lib/esm/agent/subnetStatus/index.js +63 -86
  154. package/lib/esm/agent/subnetStatus/index.js.map +1 -1
  155. package/lib/esm/agent/utils/bls.d.ts.map +1 -1
  156. package/lib/esm/agent/utils/bls.js +7 -6
  157. package/lib/esm/agent/utils/bls.js.map +1 -1
  158. package/lib/esm/agent/utils/readState.d.ts +104 -15
  159. package/lib/esm/agent/utils/readState.d.ts.map +1 -1
  160. package/lib/esm/agent/utils/readState.js +103 -16
  161. package/lib/esm/agent/utils/readState.js.map +1 -1
  162. package/lib/esm/agent/utils/target.d.ts +15 -0
  163. package/lib/esm/agent/utils/target.d.ts.map +1 -0
  164. package/lib/esm/agent/utils/target.js +23 -0
  165. package/lib/esm/agent/utils/target.js.map +1 -0
  166. package/lib/esm/candid/utils/buffer.d.ts +2 -1
  167. package/lib/esm/candid/utils/buffer.d.ts.map +1 -1
  168. package/lib/esm/candid/utils/buffer.js +5 -2
  169. package/lib/esm/candid/utils/buffer.js.map +1 -1
  170. package/lib/esm/identity/identity/delegation.d.ts +10 -3
  171. package/lib/esm/identity/identity/delegation.d.ts.map +1 -1
  172. package/lib/esm/identity/identity/delegation.js +22 -9
  173. package/lib/esm/identity/identity/delegation.js.map +1 -1
  174. package/lib/esm/identity/identity/ecdsa.d.ts +2 -2
  175. package/lib/esm/identity/identity/ecdsa.d.ts.map +1 -1
  176. package/lib/esm/identity/identity/ecdsa.js +3 -2
  177. package/lib/esm/identity/identity/ecdsa.js.map +1 -1
  178. package/lib/esm/identity/identity/ed25519.d.ts +3 -2
  179. package/lib/esm/identity/identity/ed25519.d.ts.map +1 -1
  180. package/lib/esm/identity/identity/ed25519.js +10 -7
  181. package/lib/esm/identity/identity/ed25519.js.map +1 -1
  182. package/lib/esm/identity/identity/webauthn.d.ts +4 -3
  183. package/lib/esm/identity/identity/webauthn.d.ts.map +1 -1
  184. package/lib/esm/identity/identity/webauthn.js +8 -7
  185. package/lib/esm/identity/identity/webauthn.js.map +1 -1
  186. package/lib/esm/identity/secp256k1/der.d.ts +2 -1
  187. package/lib/esm/identity/secp256k1/der.d.ts.map +1 -1
  188. package/lib/esm/identity/secp256k1/der.js.map +1 -1
  189. package/lib/esm/identity/secp256k1/pem.d.ts +4 -3
  190. package/lib/esm/identity/secp256k1/pem.d.ts.map +1 -1
  191. package/lib/esm/identity/secp256k1/pem.js +2 -2
  192. package/lib/esm/identity/secp256k1/pem.js.map +1 -1
  193. package/lib/esm/identity/secp256k1/secp256k1.d.ts +5 -4
  194. package/lib/esm/identity/secp256k1/secp256k1.d.ts.map +1 -1
  195. package/lib/esm/identity/secp256k1/secp256k1.js +10 -13
  196. package/lib/esm/identity/secp256k1/secp256k1.js.map +1 -1
  197. package/lib/esm/principal/principal.js +2 -2
  198. package/lib/esm/principal/principal.js.map +1 -1
  199. package/package.json +20 -10
  200. package/src/agent/actor.ts +0 -524
  201. package/src/agent/agent/api.ts +0 -310
  202. package/src/agent/agent/http/expiry.ts +0 -107
  203. package/src/agent/agent/http/index.ts +0 -1724
  204. package/src/agent/agent/http/transforms.ts +0 -54
  205. package/src/agent/agent/http/types.ts +0 -145
  206. package/src/agent/agent/index.ts +0 -4
  207. package/src/agent/auth.ts +0 -147
  208. package/src/agent/canister-env/index.ts +0 -192
  209. package/src/agent/canisterStatus/index.ts +0 -260
  210. package/src/agent/cbor.ts +0 -63
  211. package/src/agent/certificate.ts +0 -1058
  212. package/src/agent/constants.ts +0 -24
  213. package/src/agent/der.ts +0 -191
  214. package/src/agent/errors.ts +0 -962
  215. package/src/agent/fetch_candid.ts +0 -37
  216. package/src/agent/index.ts +0 -130
  217. package/src/agent/observable.ts +0 -49
  218. package/src/agent/polling/backoff.ts +0 -129
  219. package/src/agent/polling/index.ts +0 -238
  220. package/src/agent/polling/strategy.ts +0 -140
  221. package/src/agent/polling/types.ts +0 -28
  222. package/src/agent/public_key.ts +0 -65
  223. package/src/agent/request_id.ts +0 -99
  224. package/src/agent/subnetStatus/index.ts +0 -263
  225. package/src/agent/utils/bls.ts +0 -18
  226. package/src/agent/utils/buffer.ts +0 -64
  227. package/src/agent/utils/certificateReject.ts +0 -25
  228. package/src/agent/utils/createExpirableStore.ts +0 -31
  229. package/src/agent/utils/expirableStore.ts +0 -47
  230. package/src/agent/utils/inMemoryExpirableStore.ts +0 -49
  231. package/src/agent/utils/indexedDBExpirableStore.ts +0 -191
  232. package/src/agent/utils/leb.ts +0 -14
  233. package/src/agent/utils/random.ts +0 -30
  234. package/src/agent/utils/readState.ts +0 -180
  235. package/src/candid/candid-core.ts +0 -274
  236. package/src/candid/candid-ui.ts +0 -281
  237. package/src/candid/idl.ts +0 -2654
  238. package/src/candid/index.ts +0 -35
  239. package/src/candid/types.ts +0 -7
  240. package/src/candid/utils/bigint-math.ts +0 -26
  241. package/src/candid/utils/buffer.ts +0 -221
  242. package/src/candid/utils/hash.ts +0 -31
  243. package/src/candid/utils/leb128.ts +0 -233
  244. package/src/identity/identity/attributes.ts +0 -91
  245. package/src/identity/identity/delegation.ts +0 -411
  246. package/src/identity/identity/ecdsa.ts +0 -162
  247. package/src/identity/identity/ed25519.ts +0 -246
  248. package/src/identity/identity/partial.ts +0 -60
  249. package/src/identity/identity/webauthn.ts +0 -265
  250. package/src/identity/index.ts +0 -44
  251. package/src/identity/secp256k1/der.ts +0 -177
  252. package/src/identity/secp256k1/index.ts +0 -52
  253. package/src/identity/secp256k1/pem.ts +0 -39
  254. package/src/identity/secp256k1/secp256k1.ts +0 -276
  255. package/src/index.ts +0 -3
  256. package/src/principal/index.ts +0 -19
  257. package/src/principal/principal.ts +0 -181
  258. package/src/principal/utils/base32.ts +0 -101
  259. package/src/principal/utils/getCrc.ts +0 -52
@@ -1,181 +0,0 @@
1
- import { base32Decode, base32Encode } from './utils/base32.ts';
2
- import { getCrc32 } from './utils/getCrc.ts';
3
- import { sha224 } from '@noble/hashes/sha2';
4
- import { bytesToHex, hexToBytes } from '@noble/hashes/utils';
5
-
6
- export const JSON_KEY_PRINCIPAL = '__principal__';
7
- const SELF_AUTHENTICATING_SUFFIX = 2;
8
- const ANONYMOUS_SUFFIX = 4;
9
-
10
- const MANAGEMENT_CANISTER_PRINCIPAL_TEXT_STR = 'aaaaa-aa';
11
-
12
- export interface JsonnablePrincipal {
13
- [JSON_KEY_PRINCIPAL]: string;
14
- }
15
-
16
- export class Principal {
17
- public static anonymous(): Principal {
18
- return new this(new Uint8Array([ANONYMOUS_SUFFIX]));
19
- }
20
-
21
- /**
22
- * Utility method, returning the principal representing the management canister, decoded from the hex string `'aaaaa-aa'`
23
- * @returns {Principal} principal of the management canister
24
- */
25
- public static managementCanister(): Principal {
26
- return this.fromText(MANAGEMENT_CANISTER_PRINCIPAL_TEXT_STR);
27
- }
28
-
29
- public static selfAuthenticating(publicKey: Uint8Array): Principal {
30
- const sha = sha224(publicKey);
31
- return new this(new Uint8Array([...sha, SELF_AUTHENTICATING_SUFFIX]));
32
- }
33
-
34
- public static from(other: unknown): Principal {
35
- if (typeof other === 'string') {
36
- return Principal.fromText(other);
37
- }
38
- if (Object.getPrototypeOf(other) === Uint8Array.prototype) {
39
- return new Principal(other as Uint8Array);
40
- }
41
- if (Principal.isPrincipal(other)) {
42
- return new Principal(other._arr);
43
- }
44
-
45
- throw new Error(`Impossible to convert ${JSON.stringify(other)} to Principal.`);
46
- }
47
-
48
- public static fromHex(hex: string): Principal {
49
- return new this(hexToBytes(hex));
50
- }
51
-
52
- public static fromText(text: string): Principal {
53
- let maybePrincipal = text;
54
- // If formatted as JSON string, parse it first
55
- if (text.includes(JSON_KEY_PRINCIPAL)) {
56
- const obj = JSON.parse(text);
57
- if (JSON_KEY_PRINCIPAL in obj) {
58
- maybePrincipal = obj[JSON_KEY_PRINCIPAL];
59
- }
60
- }
61
-
62
- const canisterIdNoDash = maybePrincipal.toLowerCase().replace(/-/g, '');
63
-
64
- let arr = base32Decode(canisterIdNoDash);
65
- arr = arr.slice(4, arr.length);
66
-
67
- const principal = new this(arr);
68
- if (principal.toText() !== maybePrincipal) {
69
- throw new Error(
70
- `Principal "${principal.toText()}" does not have a valid checksum (original value "${maybePrincipal}" may not be a valid Principal ID).`,
71
- );
72
- }
73
-
74
- return principal;
75
- }
76
-
77
- public static fromUint8Array(arr: Uint8Array): Principal {
78
- return new this(arr);
79
- }
80
-
81
- public static isPrincipal(other: unknown): other is Principal {
82
- return (
83
- other instanceof Principal ||
84
- (typeof other === 'object' &&
85
- other !== null &&
86
- '_isPrincipal' in other &&
87
- (other as { _isPrincipal: boolean })['_isPrincipal'] === true &&
88
- '_arr' in other &&
89
- (other as { _arr: Uint8Array })['_arr'] instanceof Uint8Array)
90
- );
91
- }
92
-
93
- public readonly _isPrincipal = true;
94
-
95
- protected constructor(private _arr: Uint8Array) {}
96
-
97
- public isAnonymous(): boolean {
98
- return this._arr.byteLength === 1 && this._arr[0] === ANONYMOUS_SUFFIX;
99
- }
100
-
101
- public toUint8Array(): Uint8Array {
102
- return this._arr;
103
- }
104
-
105
- public toHex(): string {
106
- return bytesToHex(this._arr).toUpperCase();
107
- }
108
-
109
- public toText(): string {
110
- const checksumArrayBuf = new ArrayBuffer(4);
111
- const view = new DataView(checksumArrayBuf);
112
- view.setUint32(0, getCrc32(this._arr));
113
- const checksum = new Uint8Array(checksumArrayBuf);
114
-
115
- const array = new Uint8Array([...checksum, ...this._arr]);
116
-
117
- const result = base32Encode(array);
118
- const matches = result.match(/.{1,5}/g);
119
- if (!matches) {
120
- // This should only happen if there's no character, which is unreachable.
121
- throw new Error();
122
- }
123
- return matches.join('-');
124
- }
125
-
126
- public toString(): string {
127
- return this.toText();
128
- }
129
-
130
- /**
131
- * Serializes to JSON
132
- * @returns {JsonnablePrincipal} a JSON object with a single key, {@link JSON_KEY_PRINCIPAL}, whose value is the principal as a string
133
- */
134
- public toJSON(): JsonnablePrincipal {
135
- return { [JSON_KEY_PRINCIPAL]: this.toText() };
136
- }
137
-
138
- /**
139
- * Utility method taking a Principal to compare against. Used for determining canister ranges in certificate verification
140
- * @param {Principal} other - a {@link Principal} to compare
141
- * @returns {'lt' | 'eq' | 'gt'} `'lt' | 'eq' | 'gt'` a string, representing less than, equal to, or greater than
142
- */
143
- public compareTo(other: Principal): 'lt' | 'eq' | 'gt' {
144
- for (let i = 0; i < Math.min(this._arr.length, other._arr.length); i++) {
145
- if (this._arr[i] < other._arr[i]) {
146
- return 'lt';
147
- }
148
- if (this._arr[i] > other._arr[i]) {
149
- return 'gt';
150
- }
151
- }
152
- // Here, at least one principal is a prefix of the other principal (they could be the same)
153
- if (this._arr.length < other._arr.length) {
154
- return 'lt';
155
- }
156
- if (this._arr.length > other._arr.length) {
157
- return 'gt';
158
- }
159
- return 'eq';
160
- }
161
-
162
- /**
163
- * Utility method checking whether a provided Principal is less than or equal to the current one using the {@link Principal.compareTo} method
164
- * @param other a {@link Principal} to compare
165
- * @returns {boolean} boolean
166
- */
167
- public ltEq(other: Principal): boolean {
168
- const cmp = this.compareTo(other);
169
- return cmp == 'lt' || cmp == 'eq';
170
- }
171
-
172
- /**
173
- * Utility method checking whether a provided Principal is greater than or equal to the current one using the {@link Principal.compareTo} method
174
- * @param other a {@link Principal} to compare
175
- * @returns {boolean} boolean
176
- */
177
- public gtEq(other: Principal): boolean {
178
- const cmp = this.compareTo(other);
179
- return cmp == 'gt' || cmp == 'eq';
180
- }
181
- }
@@ -1,101 +0,0 @@
1
- const alphabet = 'abcdefghijklmnopqrstuvwxyz234567';
2
-
3
- // Build a lookup table for decoding.
4
- const lookupTable: Record<string, number> = Object.create(null);
5
- for (let i = 0; i < alphabet.length; i++) {
6
- lookupTable[alphabet[i]] = i;
7
- }
8
-
9
- // Add aliases for rfc4648.
10
- lookupTable['0'] = lookupTable.o;
11
- lookupTable['1'] = lookupTable.i;
12
-
13
- /**
14
- * @param input The Uint8Array to encode.
15
- * @returns A Base32 string encoding the input.
16
- */
17
- export function base32Encode(input: Uint8Array): string {
18
- // How many bits will we skip from the first byte.
19
- let skip = 0;
20
- // 5 high bits, carry from one byte to the next.
21
- let bits = 0;
22
-
23
- // The output string in base32.
24
- let output = '';
25
-
26
- function encodeByte(byte: number) {
27
- if (skip < 0) {
28
- // we have a carry from the previous byte
29
- bits |= byte >> -skip;
30
- } else {
31
- // no carry
32
- bits = (byte << skip) & 248;
33
- }
34
-
35
- if (skip > 3) {
36
- // Not enough data to produce a character, get us another one
37
- skip -= 8;
38
- return 1;
39
- }
40
-
41
- if (skip < 4) {
42
- // produce a character
43
- output += alphabet[bits >> 3];
44
- skip += 5;
45
- }
46
-
47
- return 0;
48
- }
49
-
50
- for (let i = 0; i < input.length; ) {
51
- i += encodeByte(input[i]);
52
- }
53
-
54
- return output + (skip < 0 ? alphabet[bits >> 3] : '');
55
- }
56
-
57
- /**
58
- * @param input The base32 encoded string to decode.
59
- */
60
- export function base32Decode(input: string): Uint8Array {
61
- // how many bits we have from the previous character.
62
- let skip = 0;
63
- // current byte we're producing.
64
- let byte = 0;
65
-
66
- const output = new Uint8Array(((input.length * 4) / 3) | 0);
67
- let o = 0;
68
-
69
- function decodeChar(char: string) {
70
- // Consume a character from the stream, store
71
- // the output in this.output. As before, better
72
- // to use update().
73
- let val = lookupTable[char.toLowerCase()];
74
- if (val === undefined) {
75
- throw new Error(`Invalid character: ${JSON.stringify(char)}`);
76
- }
77
-
78
- // move to the high bits
79
- val <<= 3;
80
- byte |= val >>> skip;
81
- skip += 5;
82
-
83
- if (skip >= 8) {
84
- // We have enough bytes to produce an output
85
- output[o++] = byte;
86
- skip -= 8;
87
-
88
- if (skip > 0) {
89
- byte = (val << (5 - skip)) & 255;
90
- } else {
91
- byte = 0;
92
- }
93
- }
94
- }
95
-
96
- for (const c of input) {
97
- decodeChar(c);
98
- }
99
-
100
- return output.slice(0, o);
101
- }
@@ -1,52 +0,0 @@
1
- // This file is translated to JavaScript from
2
- // https://lxp32.github.io/docs/a-simple-example-crc32-calculation/
3
- const lookUpTable: Uint32Array = new Uint32Array([
4
- 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3,
5
- 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91,
6
- 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
7
- 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5,
8
- 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
9
- 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
10
- 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f,
11
- 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d,
12
- 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
13
- 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
14
- 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457,
15
- 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
16
- 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb,
17
- 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9,
18
- 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
19
- 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad,
20
- 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683,
21
- 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
22
- 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7,
23
- 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
24
- 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
25
- 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79,
26
- 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f,
27
- 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
28
- 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
29
- 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21,
30
- 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
31
- 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45,
32
- 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db,
33
- 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
34
- 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf,
35
- 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,
36
- ]);
37
-
38
- /**
39
- * Calculate the CRC32 of a Uint8Array.
40
- * @param buf The Uint8Array to calculate the CRC32 of.
41
- */
42
- export function getCrc32(buf: Uint8Array): number {
43
- let crc = -1;
44
-
45
- for (let i = 0; i < buf.length; i++) {
46
- const byte = buf[i];
47
- const t = (byte ^ crc) & 0xff;
48
- crc = lookUpTable[t] ^ (crc >>> 8);
49
- }
50
-
51
- return (crc ^ -1) >>> 0;
52
- }