From 9ae1132312c6e3fbb1c3833e9cd7d9b86d549d78 Mon Sep 17 00:00:00 2001 From: Kyle Peacock Date: Thu, 11 Jan 2024 09:58:56 -0800 Subject: [PATCH 1/6] invalid JSDoc tag name "jest-environment" --- packages/candid/src/idl.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/candid/src/idl.test.ts b/packages/candid/src/idl.test.ts index b5a945590..c9ecfb112 100644 --- a/packages/candid/src/idl.test.ts +++ b/packages/candid/src/idl.test.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable @typescript-eslint/no-explicit-any */ -/** +/* * @jest-environment node */ import * as IDL from './idl'; From 34b5b0c2ed20b429d96216cc35ce9a2ab26f8d25 Mon Sep 17 00:00:00 2001 From: Kyle Peacock Date: Thu, 11 Jan 2024 10:00:38 -0800 Subject: [PATCH 2/6] idl jsdoc warnings --- packages/candid/src/idl.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/candid/src/idl.ts b/packages/candid/src/idl.ts index 382599ca1..ef6190611 100644 --- a/packages/candid/src/idl.ts +++ b/packages/candid/src/idl.ts @@ -1531,9 +1531,9 @@ export class ServiceClass extends ConstructType { } /** - * - * @param x - * @returns {string} + * Takes an unknown value and returns a string representation of it. + * @param x - unknown value + * @returns {string} string representation of the value */ function toReadableString(x: unknown): string { const str = JSON.stringify(x, (_key, value) => @@ -1547,9 +1547,9 @@ function toReadableString(x: unknown): string { /** * Encode a array of values - * @param argTypes - * @param args - * @returns {Buffer} serialised value + * @param argTypes - array of Types + * @param args - array of values + * @returns {ArrayBuffer} serialised value */ export function encode(argTypes: Array>, args: any[]): ArrayBuffer { if (args.length < argTypes.length) { From 503befcbf75f00c1e7dce22f05cdd15c91e4d735 Mon Sep 17 00:00:00 2001 From: Kyle Peacock Date: Thu, 11 Jan 2024 10:01:13 -0800 Subject: [PATCH 3/6] Missing JSDoc @param "s" description --- packages/candid/src/utils/hash.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/candid/src/utils/hash.ts b/packages/candid/src/utils/hash.ts index 423bc04dc..c8169c81a 100644 --- a/packages/candid/src/utils/hash.ts +++ b/packages/candid/src/utils/hash.ts @@ -1,7 +1,8 @@ /** * Hashes a string to a number. Algorithm can be found here: * https://caml.inria.fr/pub/papers/garrigue-polymorphic_variants-ml98.pdf - * @param s + * @param s - string to hash + * @returns number representing hashed string */ function idlHash(s: string): number { const utf8encoder = new TextEncoder(); From 7c5639f85550b3d73c44065b03ae7979ec12b229 Mon Sep 17 00:00:00 2001 From: Kyle Peacock Date: Thu, 11 Jan 2024 10:08:31 -0800 Subject: [PATCH 4/6] leb128 cleanup and strict arraybuffer type enforcement --- packages/candid/src/utils/buffer.ts | 33 +++++++++++++++++++++++++++-- packages/candid/src/utils/leb128.ts | 7 +++--- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/packages/candid/src/utils/buffer.ts b/packages/candid/src/utils/buffer.ts index dd1470d5e..5335ea947 100644 --- a/packages/candid/src/utils/buffer.ts +++ b/packages/candid/src/utils/buffer.ts @@ -50,13 +50,13 @@ export class PipeArrayBuffer { * @param length an optional amount of bytes to use for the length. */ constructor(buffer?: ArrayBuffer, length = buffer?.byteLength || 0) { - this._buffer = buffer || new ArrayBuffer(0); + this._buffer = bufFromBufLike(buffer || new ArrayBuffer(0)); this._view = new Uint8Array(this._buffer, 0, length); } get buffer(): ArrayBuffer { // Return a copy of the buffer. - return this._view.slice(); + return bufFromBufLike(this._view.slice()); } get byteLength(): number { @@ -121,3 +121,32 @@ export class PipeArrayBuffer { this._view = v; } } + +/** + * Returns a true ArrayBuffer from a Uint8Array, as Uint8Array.buffer is unsafe. + * @param {Uint8Array} arr Uint8Array to convert + * @returns ArrayBuffer + */ +export function uint8ToBuf(arr: Uint8Array): ArrayBuffer { + return new DataView(arr.buffer, arr.byteOffset, arr.byteLength).buffer; +} + +/** + * Returns a true ArrayBuffer from an ArrayBufferLike object. + * @param bufLike a buffer-like object + * @returns ArrayBuffer + */ +export function bufFromBufLike( + bufLike: ArrayBuffer | Uint8Array | DataView | ArrayBufferView | ArrayBufferLike, +): ArrayBuffer { + if (bufLike instanceof Uint8Array) { + return uint8ToBuf(bufLike); + } + if (bufLike instanceof ArrayBuffer) { + return bufLike; + } + if ('buffer' in bufLike) { + return bufLike.buffer; + } + return new Uint8Array(bufLike); +} diff --git a/packages/candid/src/utils/leb128.ts b/packages/candid/src/utils/leb128.ts index b229f2e78..44ca679a6 100644 --- a/packages/candid/src/utils/leb128.ts +++ b/packages/candid/src/utils/leb128.ts @@ -26,7 +26,7 @@ export function safeRead(pipe: Pipe, num: number): ArrayBuffer { } /** - * @param pipe + * @param pipe - PipeArrayBuffer simulating buffer-pipe api */ export function safeReadUint8(pipe: Pipe): number { const byte = pipe.readUint8(); @@ -169,8 +169,9 @@ export function writeUIntLE(value: bigint | number, byteLength: number): ArrayBu /** * - * @param value - * @param byteLength + * @param value - bigint or number + * @param byteLength - number + * @returns ArrayBuffer */ export function writeIntLE(value: bigint | number, byteLength: number): ArrayBuffer { value = BigInt(value); From 949e0d99e54cfc07597047ced26fd7abcfd9618a Mon Sep 17 00:00:00 2001 From: Kyle Peacock Date: Thu, 11 Jan 2024 10:09:01 -0800 Subject: [PATCH 5/6] npm audit --- package-lock.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index c2f1de13f..fc2cf7798 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11382,9 +11382,9 @@ "license": "ISC" }, "node_modules/follow-redirects": { - "version": "1.15.3", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.3.tgz", - "integrity": "sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q==", + "version": "1.15.4", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.4.tgz", + "integrity": "sha512-Cr4D/5wlrb0z9dgERpUL3LrmPKVDsETIJhaCMeDfuFYcqa5bldGV6wBsAN6X/vxlXQtFBMrXdXxdL8CbDTGniw==", "dev": true, "funding": [ { @@ -16628,9 +16628,9 @@ "license": "MIT" }, "node_modules/msgpackr": { - "version": "1.9.9", - "resolved": "https://registry.npmjs.org/msgpackr/-/msgpackr-1.9.9.tgz", - "integrity": "sha512-sbn6mioS2w0lq1O6PpGtsv6Gy8roWM+o3o4Sqjd6DudrL/nOugY+KyJUimoWzHnf9OkO0T6broHFnYE/R05t9A==", + "version": "1.10.1", + "resolved": "https://registry.npmjs.org/msgpackr/-/msgpackr-1.10.1.tgz", + "integrity": "sha512-r5VRLv9qouXuLiIBrLpl2d5ZvPt8svdQTl5/vMvE4nzDMyEX4sgW5yWhuBBj5UmgwOTWj8CIdSXn5sAfsHAWIQ==", "dev": true, "optionalDependencies": { "msgpackr-extract": "^3.0.2" From a510ecd8a0f94409a86a889fb7f4c84b4ad1a245 Mon Sep 17 00:00:00 2001 From: Kyle Peacock Date: Thu, 11 Jan 2024 10:13:15 -0800 Subject: [PATCH 6/6] changelog --- docs/generated/changelog.html | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/generated/changelog.html b/docs/generated/changelog.html index b3fbfbeaa..b60a5bfec 100644 --- a/docs/generated/changelog.html +++ b/docs/generated/changelog.html @@ -12,6 +12,7 @@

Agent-JS Changelog

Version x.x.x

    +
  • chore: cleans up github actions linting warnings
  • feat: replaces `secp256k1` npm package with `@noble/curves`
  • feat: enhances `.from` methods on public key classes to support unknown types, including PublicKey instances, ArrayBuffer-like objects, DER encoded public keys, and hex strings. Also introduces a new `bufFromBufLike` util
  • feat: introduces partial identities from public keys for authentication flows