From ecab8954e11bb17496d31caf9b51c0655a494d96 Mon Sep 17 00:00:00 2001 From: ilbertt Date: Tue, 9 Dec 2025 13:27:57 +0100 Subject: [PATCH] feat!: switch to `Uint8Array` for all buffers --- .../nns_proxy/tests/src/support/candid.ts | 2 +- packages/pic/src/pocket-ic-types.ts | 36 +++++++++---------- packages/pic/src/pocket-ic.ts | 12 +++---- 3 files changed, 24 insertions(+), 26 deletions(-) diff --git a/examples/nns_proxy/tests/src/support/candid.ts b/examples/nns_proxy/tests/src/support/candid.ts index c383a7f..edd2cf1 100644 --- a/examples/nns_proxy/tests/src/support/candid.ts +++ b/examples/nns_proxy/tests/src/support/candid.ts @@ -18,7 +18,7 @@ export interface UpdateElectedReplicaVersionsPayload { export function encodeUpdateElectedReplicaVersionsPayload( arg: UpdateElectedReplicaVersionsPayload, -): ArrayBuffer { +): Uint8Array { return IDL.encode([UpdateElectedReplicaVersionsPayload], [arg]); } diff --git a/packages/pic/src/pocket-ic-types.ts b/packages/pic/src/pocket-ic-types.ts index 5021048..29fc42d 100644 --- a/packages/pic/src/pocket-ic-types.ts +++ b/packages/pic/src/pocket-ic-types.ts @@ -416,15 +416,15 @@ export interface SetupCanisterOptions extends CreateCanisterOptions { /** * The WASM module to install to the canister. * If a string is passed, it is treated as a path to a file. - * If an `ArrayBufferLike` is passed, it is treated as the WASM module itself. + * If an `Uint8Array` is passed, it is treated as the WASM module itself. */ - wasm: ArrayBufferLike | string; + wasm: Uint8Array | string; /** * Candid encoded argument to pass to the canister's init function. - * Defaults to an empty ArrayBuffer. + * Defaults to an empty Uint8Array. */ - arg?: ArrayBufferLike; + arg?: Uint8Array; /** * The principal to setup the canister as. @@ -584,15 +584,15 @@ export interface InstallCodeOptions { /** * The WASM module to install to the canister. * If a string is passed, it is treated as a path to a file. - * If an `ArrayBufferLike` is passed, it is treated as the WASM module itself. + * If an `Uint8Array` is passed, it is treated as the WASM module itself. */ - wasm: ArrayBufferLike | string; + wasm: Uint8Array | string; /** * Candid encoded argument to pass to the canister's init function. - * Defaults to an empty ArrayBuffer. + * Defaults to an empty Uint8Array. */ - arg?: ArrayBufferLike; + arg?: Uint8Array; /** * The principal to install the code as. @@ -622,14 +622,14 @@ export interface ReinstallCodeOptions { /** * The WASM module to install to the canister. * If a string is passed, it is treated as a path to a file. - * If an `ArrayBufferLike` is passed, it is treated as the WASM module itself. + * If an `Uint8Array` is passed, it is treated as the WASM module itself. */ - wasm: ArrayBufferLike | string; + wasm: Uint8Array | string; /** * Candid encoded argument to pass to the canister's init function. */ - arg?: ArrayBufferLike; + arg?: Uint8Array; /** * The Principal to send the request as. @@ -654,14 +654,14 @@ export interface UpgradeCanisterOptions { /** * The WASM module to install to the canister. * If a string is passed, it is treated as a path to a file. - * If an `ArrayBufferLike` is passed, it is treated as the WASM module itself. + * If an `Uint8Array` is passed, it is treated as the WASM module itself. */ - wasm: ArrayBufferLike | string; + wasm: Uint8Array | string; /** * Candid encoded argument to pass to the canister's init function. */ - arg?: ArrayBufferLike; + arg?: Uint8Array; /** * The Principal to send the request as. @@ -724,9 +724,9 @@ export interface QueryCallOptions { /** * A Candid encoded argument to pass to the canister's method. - * Defaults to an empty ArrayBuffer. + * Defaults to an empty Uint8Array. */ - arg?: ArrayBufferLike; + arg?: Uint8Array; /** * The ID of the subnet that the canister resides on. @@ -760,9 +760,9 @@ export interface UpdateCallOptions { /** * A Candid encoded argument to pass to the canister's method. - * Defaults to an empty ArrayBuffer. + * Defaults to an empty Uint8Array. */ - arg?: ArrayBufferLike; + arg?: Uint8Array; /** * The ID of the subnet that the canister resides on. diff --git a/packages/pic/src/pocket-ic.ts b/packages/pic/src/pocket-ic.ts index 41a46fe..3d8c970 100644 --- a/packages/pic/src/pocket-ic.ts +++ b/packages/pic/src/pocket-ic.ts @@ -678,7 +678,7 @@ export class PocketIc { arg = new Uint8Array(), sender = Principal.anonymous(), targetSubnetId, - }: QueryCallOptions): Promise { + }: QueryCallOptions): Promise { const res = await this.client.queryCall({ canisterId, method, @@ -731,7 +731,7 @@ export class PocketIc { arg = new Uint8Array(), sender = Principal.anonymous(), targetSubnetId, - }: UpdateCallOptions): Promise { + }: UpdateCallOptions): Promise { const res = await this.client.updateCall({ canisterId, method, @@ -1056,7 +1056,7 @@ export class PocketIc { * await picServer.stop(); * ``` */ - public async getPubKey(subnetId: Principal): Promise { + public async getPubKey(subnetId: Principal): Promise { return await this.client.getPubKey({ subnetId }); } @@ -1289,7 +1289,7 @@ export class PocketIc { */ public async setStableMemory( canisterId: Principal, - stableMemory: ArrayBufferLike, + stableMemory: Uint8Array, ): Promise { const { blobId } = await this.client.uploadBlob({ blob: new Uint8Array(stableMemory), @@ -1322,9 +1322,7 @@ export class PocketIc { * await picServer.stop(); * ``` */ - public async getStableMemory( - canisterId: Principal, - ): Promise { + public async getStableMemory(canisterId: Principal): Promise { const { blob } = await this.client.getStableMemory({ canisterId }); return blob;