Skip to content

Commit eb3fa49

Browse files
authored
chore: GitHub actions warning cleanup (#819)
* invalid JSDoc tag name "jest-environment" * idl jsdoc warnings * Missing JSDoc @param "s" description * leb128 cleanup and strict arraybuffer type enforcement * npm audit * changelog fixes #811
1 parent e46045b commit eb3fa49

File tree

7 files changed

+51
-19
lines changed

7 files changed

+51
-19
lines changed

docs/generated/changelog.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ <h1>Agent-JS Changelog</h1>
1212
<section>
1313
<h2>Version x.x.x</h2>
1414
<ul>
15+
<li>chore: cleans up github actions linting warnings</li>
1516
<li>feat: replaces `secp256k1` npm package with `@noble/curves`</li>
1617
<li>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</li>
1718
<li>feat: introduces partial identities from public keys for authentication flows</li>

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/candid/src/idl.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable @typescript-eslint/no-unused-vars */
22
/* eslint-disable @typescript-eslint/no-explicit-any */
3-
/**
3+
/*
44
* @jest-environment node
55
*/
66
import * as IDL from './idl';

packages/candid/src/idl.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,9 +1531,9 @@ export class ServiceClass extends ConstructType<PrincipalId> {
15311531
}
15321532

15331533
/**
1534-
*
1535-
* @param x
1536-
* @returns {string}
1534+
* Takes an unknown value and returns a string representation of it.
1535+
* @param x - unknown value
1536+
* @returns {string} string representation of the value
15371537
*/
15381538
function toReadableString(x: unknown): string {
15391539
const str = JSON.stringify(x, (_key, value) =>
@@ -1547,9 +1547,9 @@ function toReadableString(x: unknown): string {
15471547

15481548
/**
15491549
* Encode a array of values
1550-
* @param argTypes
1551-
* @param args
1552-
* @returns {Buffer} serialised value
1550+
* @param argTypes - array of Types
1551+
* @param args - array of values
1552+
* @returns {ArrayBuffer} serialised value
15531553
*/
15541554
export function encode(argTypes: Array<Type<any>>, args: any[]): ArrayBuffer {
15551555
if (args.length < argTypes.length) {

packages/candid/src/utils/buffer.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ export class PipeArrayBuffer {
5050
* @param length an optional amount of bytes to use for the length.
5151
*/
5252
constructor(buffer?: ArrayBuffer, length = buffer?.byteLength || 0) {
53-
this._buffer = buffer || new ArrayBuffer(0);
53+
this._buffer = bufFromBufLike(buffer || new ArrayBuffer(0));
5454
this._view = new Uint8Array(this._buffer, 0, length);
5555
}
5656

5757
get buffer(): ArrayBuffer {
5858
// Return a copy of the buffer.
59-
return this._view.slice();
59+
return bufFromBufLike(this._view.slice());
6060
}
6161

6262
get byteLength(): number {
@@ -121,3 +121,32 @@ export class PipeArrayBuffer {
121121
this._view = v;
122122
}
123123
}
124+
125+
/**
126+
* Returns a true ArrayBuffer from a Uint8Array, as Uint8Array.buffer is unsafe.
127+
* @param {Uint8Array} arr Uint8Array to convert
128+
* @returns ArrayBuffer
129+
*/
130+
export function uint8ToBuf(arr: Uint8Array): ArrayBuffer {
131+
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength).buffer;
132+
}
133+
134+
/**
135+
* Returns a true ArrayBuffer from an ArrayBufferLike object.
136+
* @param bufLike a buffer-like object
137+
* @returns ArrayBuffer
138+
*/
139+
export function bufFromBufLike(
140+
bufLike: ArrayBuffer | Uint8Array | DataView | ArrayBufferView | ArrayBufferLike,
141+
): ArrayBuffer {
142+
if (bufLike instanceof Uint8Array) {
143+
return uint8ToBuf(bufLike);
144+
}
145+
if (bufLike instanceof ArrayBuffer) {
146+
return bufLike;
147+
}
148+
if ('buffer' in bufLike) {
149+
return bufLike.buffer;
150+
}
151+
return new Uint8Array(bufLike);
152+
}

packages/candid/src/utils/hash.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/**
22
* Hashes a string to a number. Algorithm can be found here:
33
* https://caml.inria.fr/pub/papers/garrigue-polymorphic_variants-ml98.pdf
4-
* @param s
4+
* @param s - string to hash
5+
* @returns number representing hashed string
56
*/
67
function idlHash(s: string): number {
78
const utf8encoder = new TextEncoder();

packages/candid/src/utils/leb128.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function safeRead(pipe: Pipe, num: number): ArrayBuffer {
2626
}
2727

2828
/**
29-
* @param pipe
29+
* @param pipe - PipeArrayBuffer simulating buffer-pipe api
3030
*/
3131
export function safeReadUint8(pipe: Pipe): number {
3232
const byte = pipe.readUint8();
@@ -169,8 +169,9 @@ export function writeUIntLE(value: bigint | number, byteLength: number): ArrayBu
169169

170170
/**
171171
*
172-
* @param value
173-
* @param byteLength
172+
* @param value - bigint or number
173+
* @param byteLength - number
174+
* @returns ArrayBuffer
174175
*/
175176
export function writeIntLE(value: bigint | number, byteLength: number): ArrayBuffer {
176177
value = BigInt(value);

0 commit comments

Comments
 (0)