New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@agoric/internal

Package Overview
Dependencies
Maintainers
10
Versions
1869
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@agoric/internal - npm Package Compare versions

Comparing version 0.3.3-dev-74be420.0 to 0.3.3-dev-74fc45b.0

src/chain-utils.d.ts

33

package.json
{
"name": "@agoric/internal",
"version": "0.3.3-dev-74be420.0+74be420",
"version": "0.3.3-dev-74fc45b.0+74fc45b",
"description": "Externally unsupported utilities internal to agoric-sdk",

@@ -13,3 +13,3 @@ "type": "module",

"prepack": "tsc --build tsconfig.build.json",
"postpack": "git clean -f '*.d.ts*'",
"postpack": "git clean -f '*.d.ts*' '*.tsbuildinfo'",
"test": "ava",

@@ -24,12 +24,12 @@ "test:nyc": "exit 0",

"dependencies": {
"@agoric/base-zone": "0.1.1-dev-74be420.0+74be420",
"@endo/common": "^1.2.5",
"@endo/errors": "^1.2.5",
"@endo/far": "^1.1.5",
"@endo/init": "^1.1.4",
"@endo/marshal": "^1.5.3",
"@endo/pass-style": "^1.4.3",
"@endo/patterns": "^1.4.3",
"@endo/promise-kit": "^1.1.5",
"@endo/stream": "^1.2.5",
"@agoric/base-zone": "0.1.1-dev-74fc45b.0+74fc45b",
"@endo/common": "^1.2.9",
"@endo/errors": "^1.2.9",
"@endo/far": "^1.1.10",
"@endo/init": "^1.1.8",
"@endo/marshal": "^1.6.3",
"@endo/pass-style": "^1.4.8",
"@endo/patterns": "^1.4.8",
"@endo/promise-kit": "^1.1.9",
"@endo/stream": "^1.2.9",
"anylogger": "^0.21.0",

@@ -39,4 +39,5 @@ "jessie.js": "^0.3.4"

"devDependencies": {
"@endo/exo": "^1.5.3",
"@endo/init": "^1.1.4",
"@agoric/cosmic-proto": "0.4.1-dev-74fc45b.0+74fc45b",
"@endo/exo": "^1.5.8",
"@endo/init": "^1.1.8",
"ava": "^5.3.0",

@@ -63,5 +64,5 @@ "tsd": "^0.31.1"

"typeCoverage": {
"atLeast": 93.32
"atLeast": 93.04
},
"gitHead": "74be420fcca6eb43ebd8e85f574e6c06949e2642"
"gitHead": "74fc45b3588986de37f6a84347058592dc1d529b"
}

@@ -13,7 +13,7 @@ **NOTE: unsupported**

It is meant to be a home for modules that have no Agoric-specific dependencies themselves. It does depend on a these other @agoric packages but they are all destined to migrate out of the repo,
It is meant to be a home for modules that have no dependencies on other packages in this repository, except for the following packages that do not theirselves depend upon any other @agoric packages and may be destined for migration elsewhere:
- base-zone
- store
- assert
- [base-zone](../base-zone)
- [store](../store)
- [cosmic-proto](../cosmic-proto)

@@ -20,0 +20,0 @@ This package may not take dependencies on any others in this repository.

@@ -0,11 +1,56 @@

/**
* Types of messages used for communication between a cosmos-sdk blockchain node
* and its paired swingset VM, especially for the ABCI lifecycle. See:
*
* - https://github.com/tendermint/tendermint/blob/v0.34.x/spec/abci/abci.md#block-execution
* - ../../../golang/cosmos/vm/action.go
* - ../../../golang/cosmos/app/app.go
* - ../../../golang/cosmos/x/swingset/abci.go
* - ../../../golang/cosmos/x/swingset/keeper/swing_store_exports_handler.go
* - ../../cosmic-swingset/src/chain-main.js
* - ../../cosmic-swingset/src/launch-chain.js
*/
export type SwingsetMessageType = (typeof SwingsetMessageType)[keyof typeof SwingsetMessageType];
export namespace SwingsetMessageType {
let AG_COSMOS_INIT: "AG_COSMOS_INIT";
let BEGIN_BLOCK: "BEGIN_BLOCK";
let END_BLOCK: "END_BLOCK";
let COMMIT_BLOCK: "COMMIT_BLOCK";
let AFTER_COMMIT_BLOCK: "AFTER_COMMIT_BLOCK";
let SWING_STORE_EXPORT: "SWING_STORE_EXPORT";
}
export const AG_COSMOS_INIT: "AG_COSMOS_INIT";
export const SWING_STORE_EXPORT: "SWING_STORE_EXPORT";
export const BEGIN_BLOCK: "BEGIN_BLOCK";
export const CALCULATE_FEES_IN_BEANS: "CALCULATE_FEES_IN_BEANS";
export const CORE_EVAL: "CORE_EVAL";
export const DELIVER_INBOUND: "DELIVER_INBOUND";
export const END_BLOCK: "END_BLOCK";
export const COMMIT_BLOCK: "COMMIT_BLOCK";
export const AFTER_COMMIT_BLOCK: "AFTER_COMMIT_BLOCK";
export const SWING_STORE_EXPORT: "SWING_STORE_EXPORT";
/**
* Types of "action" messages consumed by the swingset VM from actionQueue or
* highPriorityQueue during END_BLOCK. See:
*
* - ../../../golang/cosmos/x/swingset/keeper/msg_server.go
* - ../../../golang/cosmos/x/swingset/keeper/proposal.go
* - ../../../golang/cosmos/x/vbank/vbank.go
* - ../../../golang/cosmos/x/vibc/handler.go
* - ../../../golang/cosmos/x/vibc/keeper/triggers.go
* - ../../../golang/cosmos/x/vibc/types/ibc_module.go
*/
export type QueuedActionType = (typeof QueuedActionType)[keyof typeof QueuedActionType];
export namespace QueuedActionType {
let CORE_EVAL: "CORE_EVAL";
let DELIVER_INBOUND: "DELIVER_INBOUND";
let IBC_EVENT: "IBC_EVENT";
let INSTALL_BUNDLE: "INSTALL_BUNDLE";
let PLEASE_PROVISION: "PLEASE_PROVISION";
let VBANK_BALANCE_UPDATE: "VBANK_BALANCE_UPDATE";
let WALLET_ACTION: "WALLET_ACTION";
let WALLET_SPEND_ACTION: "WALLET_SPEND_ACTION";
let VTRANSFER_IBC_EVENT: "VTRANSFER_IBC_EVENT";
let KERNEL_UPGRADE_EVENTS: "KERNEL_UPGRADE_EVENTS";
}
export const CORE_EVAL: "CORE_EVAL";
export const DELIVER_INBOUND: "DELIVER_INBOUND";
export const IBC_EVENT: "IBC_EVENT";
export const INSTALL_BUNDLE: "INSTALL_BUNDLE";
export const PLEASE_PROVISION: "PLEASE_PROVISION";

@@ -15,4 +60,4 @@ export const VBANK_BALANCE_UPDATE: "VBANK_BALANCE_UPDATE";

export const WALLET_SPEND_ACTION: "WALLET_SPEND_ACTION";
export const INSTALL_BUNDLE: "INSTALL_BUNDLE";
export const VTRANSFER_IBC_EVENT: "VTRANSFER_IBC_EVENT";
export const KERNEL_UPGRADE_EVENTS: "KERNEL_UPGRADE_EVENTS";
//# sourceMappingURL=action-types.d.ts.map
// @jessie-check
export const AG_COSMOS_INIT = 'AG_COSMOS_INIT';
export const SWING_STORE_EXPORT = 'SWING_STORE_EXPORT';
export const BEGIN_BLOCK = 'BEGIN_BLOCK';
export const CALCULATE_FEES_IN_BEANS = 'CALCULATE_FEES_IN_BEANS';
export const CORE_EVAL = 'CORE_EVAL';
export const DELIVER_INBOUND = 'DELIVER_INBOUND';
export const END_BLOCK = 'END_BLOCK';
export const COMMIT_BLOCK = 'COMMIT_BLOCK';
export const AFTER_COMMIT_BLOCK = 'AFTER_COMMIT_BLOCK';
export const IBC_EVENT = 'IBC_EVENT';
export const PLEASE_PROVISION = 'PLEASE_PROVISION';
export const VBANK_BALANCE_UPDATE = 'VBANK_BALANCE_UPDATE';
export const WALLET_ACTION = 'WALLET_ACTION';
export const WALLET_SPEND_ACTION = 'WALLET_SPEND_ACTION';
export const INSTALL_BUNDLE = 'INSTALL_BUNDLE';
export const VTRANSFER_IBC_EVENT = 'VTRANSFER_IBC_EVENT';
/**
* Types of messages used for communication between a cosmos-sdk blockchain node
* and its paired swingset VM, especially for the ABCI lifecycle. See:
*
* - https://github.com/tendermint/tendermint/blob/v0.34.x/spec/abci/abci.md#block-execution
* - ../../../golang/cosmos/vm/action.go
* - ../../../golang/cosmos/app/app.go
* - ../../../golang/cosmos/x/swingset/abci.go
* - ../../../golang/cosmos/x/swingset/keeper/swing_store_exports_handler.go
* - ../../cosmic-swingset/src/chain-main.js
* - ../../cosmic-swingset/src/launch-chain.js
*
* @enum {(typeof SwingsetMessageType)[keyof typeof SwingsetMessageType]}
*/
export const SwingsetMessageType = /** @type {const} */ ({
AG_COSMOS_INIT: 'AG_COSMOS_INIT', // used to synchronize at process launch
BEGIN_BLOCK: 'BEGIN_BLOCK',
END_BLOCK: 'END_BLOCK',
COMMIT_BLOCK: 'COMMIT_BLOCK',
AFTER_COMMIT_BLOCK: 'AFTER_COMMIT_BLOCK',
SWING_STORE_EXPORT: 'SWING_STORE_EXPORT', // used to synchronize data export
});
harden(SwingsetMessageType);
// TODO: Update all imports to use SwingsetMessageType. But until then...
export const {
AG_COSMOS_INIT,
BEGIN_BLOCK,
END_BLOCK,
COMMIT_BLOCK,
AFTER_COMMIT_BLOCK,
SWING_STORE_EXPORT,
} = SwingsetMessageType;
/**
* Types of "action" messages consumed by the swingset VM from actionQueue or
* highPriorityQueue during END_BLOCK. See:
*
* - ../../../golang/cosmos/x/swingset/keeper/msg_server.go
* - ../../../golang/cosmos/x/swingset/keeper/proposal.go
* - ../../../golang/cosmos/x/vbank/vbank.go
* - ../../../golang/cosmos/x/vibc/handler.go
* - ../../../golang/cosmos/x/vibc/keeper/triggers.go
* - ../../../golang/cosmos/x/vibc/types/ibc_module.go
*
* @enum {(typeof QueuedActionType)[keyof typeof QueuedActionType]}
*/
export const QueuedActionType = /** @type {const} */ ({
CORE_EVAL: 'CORE_EVAL',
DELIVER_INBOUND: 'DELIVER_INBOUND',
IBC_EVENT: 'IBC_EVENT',
INSTALL_BUNDLE: 'INSTALL_BUNDLE',
PLEASE_PROVISION: 'PLEASE_PROVISION',
VBANK_BALANCE_UPDATE: 'VBANK_BALANCE_UPDATE',
WALLET_ACTION: 'WALLET_ACTION',
WALLET_SPEND_ACTION: 'WALLET_SPEND_ACTION',
VTRANSFER_IBC_EVENT: 'VTRANSFER_IBC_EVENT',
KERNEL_UPGRADE_EVENTS: 'KERNEL_UPGRADE_EVENTS',
});
harden(QueuedActionType);
// TODO: Update all imports to use QueuedActionType. But until then...
export const {
CORE_EVAL,
DELIVER_INBOUND,
IBC_EVENT,
INSTALL_BUNDLE,
PLEASE_PROVISION,
VBANK_BALANCE_UPDATE,
WALLET_ACTION,
WALLET_SPEND_ACTION,
VTRANSFER_IBC_EVENT,
KERNEL_UPGRADE_EVENTS,
} = QueuedActionType;

@@ -18,3 +18,3 @@ export function callSync<I extends (...args: any[]) => any>(callback: SyncCallback<I>, ...args: Parameters<I>): ReturnType<I>;

tag?: string | undefined;
} | undefined): MakeAttenuator<any>;
}): MakeAttenuator<any>;
export type MakeAttenuator<T extends import("@endo/exo").Methods> = (...args: Parameters<ReturnType<(<M extends PropertyKey>(zone: import("@agoric/base-zone").Zone, methodNames: M[], { interfaceGuard, tag }?: {

@@ -21,0 +21,0 @@ interfaceGuard?: import("@endo/patterns").InterfaceGuard<{ [K in M]: import("@endo/patterns").MethodGuard; }> | undefined;

@@ -0,1 +1,5 @@

/**
* Event source ids used by the bridge device.
*/
export type BridgeId = (typeof BridgeId)[keyof typeof BridgeId];
export namespace BridgeId {

@@ -33,3 +37,2 @@ let BANK: "bank";

}
export type BridgeIdValue = (typeof BridgeId)[keyof typeof BridgeId];
//# sourceMappingURL=config.d.ts.map

@@ -18,2 +18,4 @@ // @ts-check

* Event source ids used by the bridge device.
*
* @enum {(typeof BridgeId)[keyof typeof BridgeId]}
*/

@@ -32,3 +34,2 @@ export const BridgeId = /** @type {const} */ ({

harden(BridgeId);
/** @typedef {(typeof BridgeId)[keyof typeof BridgeId]} BridgeIdValue */

@@ -35,0 +36,0 @@ export const CosmosInitKeyToBridgeId = {

@@ -1,2 +0,2 @@

export function NonNullish<T>(val: T | null | undefined, optDetails?: string | undefined): T;
export function NonNullish<T>(val: T | null | undefined, optDetails?: string): T;
//# sourceMappingURL=errors.d.ts.map
export * from "./config.js";
export * from "./debug.js";
export * from "./errors.js";
export * from "./utils.js";
export * from "./js-utils.js";
export * from "./method-tools.js";
export * from "./ses-utils.js";
export * from "./typeCheck.js";
export * from "./typeGuards.js";
export * from "./types.js";
export * from "./types-index.js";
export { pureDataMarshaller } from "./marshal.js";
export { objectMap } from "@endo/common/object-map.js";

@@ -10,0 +12,0 @@ export { objectMetaMap } from "@endo/common/object-meta-map.js";

@@ -8,4 +8,6 @@ // @jessie-check

export * from './errors.js';
export * from './utils.js';
export * from './js-utils.js';
export { pureDataMarshaller } from './marshal.js';
export * from './method-tools.js';
export * from './ses-utils.js';
export * from './typeCheck.js';

@@ -15,3 +17,3 @@ export * from './typeGuards.js';

// eslint-disable-next-line import/export -- just types
export * from './types.js';
export * from './types-index.js';

@@ -18,0 +20,0 @@ export { objectMap } from '@endo/common/object-map.js';

@@ -16,19 +16,8 @@ /**

sequence?: boolean | undefined;
} | undefined): import("@endo/exo").Guarded<{
}): import("@endo/exo").Guarded<{
getPath(): string;
/**
* @deprecated use getPath
* @type {() => Promise<VStorageKey>}
*/
getStoreKey(): Promise<VStorageKey>;
/**
* @type {(
* name: string,
* childNodeOptions?: { sequence?: boolean },
* ) => StorageNode}
*/
makeChildNode(name: string, childNodeOptions?: {
sequence?: boolean;
}): StorageNode;
/** @type {(value: string) => Promise<void>} */
setValue(value: string): Promise<void>;

@@ -54,17 +43,6 @@ }>;

getPath(): string;
/**
* @deprecated use getPath
* @type {() => Promise<VStorageKey>}
*/
getStoreKey(): Promise<VStorageKey>;
/**
* @type {(
* name: string,
* childNodeOptions?: { sequence?: boolean },
* ) => StorageNode}
*/
makeChildNode(name: string, childNodeOptions?: {
sequence?: boolean;
}): StorageNode;
/** @type {(value: string) => Promise<void>} */
setValue(value: string): Promise<void>;

@@ -71,0 +49,0 @@ }>;

// @ts-check
import { Fail } from '@endo/errors';
import { E } from '@endo/far';
import { E, Far } from '@endo/far';
import { M } from '@endo/patterns';

@@ -281,3 +281,6 @@ import { makeHeapZone } from '@agoric/base-zone/heap.js';

// XXX re-use "ChainStorage" methods above which don't actually depend on chains
return makeChainStorageRoot(() => null, 'null');
return makeChainStorageRoot(
Far('NullMessenger', () => null),
'null',
);
};

@@ -284,0 +287,0 @@

export default engineGC;
declare const engineGC: () => void;
declare const engineGC: GCFunction;
//# sourceMappingURL=engine-gc.d.ts.map

@@ -1,2 +0,2 @@

/* global Buffer */
/* eslint-env node */
import { Transform } from 'stream';

@@ -3,0 +3,0 @@

@@ -6,5 +6,5 @@ export function makeBoardRemote({ boardId, iface }: {

export function slotToBoardRemote(boardId: string, iface: string): BoardRemote;
export function boardSlottingMarshaller(slotToVal?: ((slot: string, iface: string) => any) | undefined): Omit<import("@endo/marshal").Marshal<string | null>, "serialize" | "unserialize">;
export function boardSlottingMarshaller(slotToVal?: (slot: string, iface: string) => any): Omit<import("@endo/marshal").Marshal<string | null>, "serialize" | "unserialize">;
export function unmarshalFromVstorage(data: Map<string, string>, key: string, fromCapData: ReturnType<typeof import("@endo/marshal").makeMarshal>["fromCapData"], index: number): any;
export function makeHistoryReviver(entries: [string, string][], slotToVal?: ((slot: string, iface?: string) => any) | undefined): {
export function makeHistoryReviver(entries: [string, string][], slotToVal?: (slot: string, iface?: string) => any): {
getItem: (key: string) => any;

@@ -14,2 +14,8 @@ children: (prefix: string) => string[];

};
export const pureDataMarshaller: {
toCapData: import("@endo/marshal").ToCapData<import("@endo/marshal").CapData<unknown>>;
fromCapData: import("@endo/marshal").FromCapData<import("@endo/marshal").CapData<unknown>>;
serialize: import("@endo/marshal").ToCapData<import("@endo/marshal").CapData<unknown>>;
unserialize: import("@endo/marshal").FromCapData<import("@endo/marshal").CapData<unknown>>;
};
/**

@@ -16,0 +22,0 @@ * Should be a union with Remotable, but that's `any`, making this type

@@ -138,1 +138,8 @@ // @ts-check

};
/** @param {import('@endo/marshal').CapData<unknown>} cap */
const rejectOCap = cap => Fail`${cap} is not pure data`;
export const pureDataMarshaller = makeMarshal(rejectOCap, rejectOCap, {
serializeBodyFormat: 'smallcaps',
});
harden(pureDataMarshaller);

@@ -14,3 +14,3 @@ /**

*/
export function decode(data: Buffer, optMaxChunkSize?: number | undefined): {
export function decode(data: Buffer, optMaxChunkSize?: number): {
leftover: Buffer;

@@ -23,4 +23,4 @@ payloads: Buffer[];

*/
export function netstringDecoderStream(optMaxChunkSize?: number | undefined): Transform;
export function netstringDecoderStream(optMaxChunkSize?: number): Transform;
import { Transform } from 'stream';
//# sourceMappingURL=netstring.d.ts.map

@@ -1,2 +0,2 @@

/* global Buffer */
/* eslint-env node */
import { Fail } from '@endo/errors';

@@ -92,2 +92,3 @@

export function netstringDecoderStream(optMaxChunkSize) {
/** @type {Buffer<ArrayBufferLike>} */
let buffered = Buffer.from('');

@@ -94,0 +95,0 @@ /**

@@ -16,4 +16,4 @@ /**

*/
constructor(options?: (import("stream").TransformOptions & BufferLineTransformOptions) | undefined);
_breakValue: string | number | Buffer;
constructor(options?: import("node:stream").TransformOptions & BufferLineTransformOptions);
_breakValue: string | number | Buffer<ArrayBufferLike>;
_breakEncoding: BufferEncoding | undefined;

@@ -38,3 +38,3 @@ _breakLength: number;

*/
break?: string | number | Buffer | undefined;
break?: string | number | Buffer<ArrayBufferLike> | undefined;
/**

@@ -41,0 +41,0 @@ * if break is a string, the encoding

@@ -1,2 +0,2 @@

/* global Buffer */
/* eslint-env node */
/* eslint-disable no-underscore-dangle */

@@ -3,0 +3,0 @@

@@ -1,2 +0,2 @@

/* global process */
/* eslint-env node */
// Use modules not prefixed with `node:` since some deploy scripts may

@@ -3,0 +3,0 @@ // still be running in esm emulation

@@ -1,2 +0,2 @@

export function fsStreamReady(stream: import("fs").ReadStream | import("fs").WriteStream): Promise<void>;
export function fsStreamReady(stream: import("fs").ReadStream | import("fs").WriteStream | import("net").Socket): Promise<void>;
export function makeFsStreamWriter(filePath: string | undefined | null): Promise<{

@@ -3,0 +3,0 @@ write: (data: any) => Promise<void>;

import { createWriteStream } from 'node:fs';
import process from 'node:process';
import { open } from 'node:fs/promises';
/**
* @param {import('fs').ReadStream | import('fs').WriteStream} stream
* @param {import('fs').ReadStream
* | import('fs').WriteStream
* | import('net').Socket} stream
* @returns {Promise<void>}

@@ -21,3 +24,3 @@ */

const onReady = () => {
cleanup(); // eslint-disable-line no-use-before-define
cleanup();
resolve();

@@ -28,3 +31,3 @@ };

const onError = err => {
cleanup(); // eslint-disable-line no-use-before-define
cleanup();
reject(err);

@@ -53,5 +56,7 @@ };

const handle = await open(filePath, 'a');
const handle = await (filePath !== '-' ? open(filePath, 'a') : undefined);
const stream = createWriteStream(noPath, { fd: handle.fd });
const stream = handle
? createWriteStream(noPath, { fd: handle.fd })
: process.stdout;
await fsStreamReady(stream);

@@ -62,27 +67,31 @@

const write = async data => {
if (closed) {
throw Error('Stream closed');
}
/** @type {Promise<void>} */
const written = new Promise((resolve, reject) => {
stream.write(data, err => {
if (err) {
reject(err);
} else {
resolve();
}
});
});
const updateFlushed = p => {
flushed = flushed.then(
() => written,
async err =>
Promise.reject(
written.then(
() => err,
writtenError => AggregateError([err, writtenError]),
),
() => p,
err =>
p.then(
() => Promise.reject(err),
pError =>
Promise.reject(
pError !== err ? AggregateError([err, pError]) : err,
),
),
);
flushed.catch(() => {});
};
const write = async data => {
/** @type {Promise<void>} */
const written = closed
? Promise.reject(Error('Stream closed'))
: new Promise((resolve, reject) => {
stream.write(data, err => {
if (err) {
reject(err);
} else {
resolve();
}
});
});
updateFlushed(written);
return written;

@@ -93,3 +102,3 @@ };

await flushed;
await handle.sync().catch(err => {
await handle?.sync().catch(err => {
if (err.code === 'EINVAL') {

@@ -103,8 +112,12 @@ return;

const close = async () => {
// TODO: Consider creating a single Error here to use a write rejection
closed = true;
await flush();
stream.close();
// @ts-expect-error calling a possibly missing method
stream.close?.();
};
stream.on('error', err => updateFlushed(Promise.reject(err)));
return harden({ write, flush, close });
};

@@ -25,3 +25,2 @@ import process from 'node:process';

process.off('beforeExit', shutdown);
// eslint-disable-next-line no-use-before-define
process.off('uncaughtException', uncaughtShutdown);

@@ -28,0 +27,0 @@ verbose && console.error(`Shutting down cleanly...`);

@@ -1,2 +0,2 @@

export function slotToRemotable(_slotId: string, iface?: string): import("@endo/marshal").RemotableObject<string> & import("@endo/eventual-send").RemotableBrand<{}, {}>;
export function slotToRemotable(_slotId: string, iface?: string): import("@endo/pass-style").RemotableObject<string> & import("@endo/eventual-send").RemotableBrand<{}, {}>;
/**

@@ -12,2 +12,6 @@ * A basic marshaller whose unserializer produces Remotables. It can only

};
export namespace defaultSerializer {
let parse: (text: string) => unknown;
let stringify: (obj: any) => string;
}
export const slotStringUnserialize: (capData: any) => any;

@@ -24,7 +28,11 @@ export function makeFakeStorageKit(rootPath: string, rootOptions?: Parameters<typeof makeChainStorageRoot>[2]): {

data: Map<string, string>;
getValues: (path: string) => string[];
messages: StorageMessage[];
toStorage: (message: StorageMessage) => string | number | any[] | {
toStorage: ((message: StorageMessage) => string | number | any[] | {
storeName: string;
storeSubkey: string;
} | null | undefined;
} | null | undefined) & import("@endo/pass-style").RemotableObject<`Alleged: ${string}`> & import("@endo/eventual-send").RemotableBrand<{}, (message: StorageMessage) => string | number | any[] | {
storeName: string;
storeSubkey: string;
} | null | undefined>;
};

@@ -40,3 +48,5 @@ export function makeMockChainStorageRoot(): MockChainStorageRoot;

replacement: string;
} | {})): Promise<void>;
} | {}) & {
showValue?: (v: string) => unknown;
}): Promise<void>;
export type FakeStorageKit = ReturnType<typeof makeFakeStorageKit>;

@@ -43,0 +53,0 @@ export type MockChainStorageRootMethods = {

@@ -5,5 +5,6 @@ // @ts-check

import { makeMarshal, Remotable } from '@endo/marshal';
import { unmarshalFromVstorage } from './marshal.js';
import { makeTracer } from './debug.js';
import { NonNullish } from './errors.js';
import { isStreamCell, makeChainStorageRoot } from './lib-chainStorage.js';
import { unmarshalFromVstorage } from './marshal.js';
import { bindAllMethods } from './method-tools.js';

@@ -38,2 +39,12 @@ import { eventLoopIteration } from './testing-utils.js';

/**
* Serialize/deserialize functions using {@link defaultMarshaller}
*/
export const defaultSerializer = {
/** @type {(text: string) => unknown} */
parse: txt => defaultMarshaller.fromCapData(JSON.parse(txt)),
/** @type {(obj: any) => string} */
stringify: obj => JSON.stringify(defaultMarshaller.toCapData(obj)),
};
/**
* A deserializer which produces slot strings instead of Remotables, so if `a =

@@ -113,79 +124,98 @@ * Far('iface')`, and serializing `{ a }` into `capData` assigned it slot

const messages = [];
/** @param {StorageMessage} message */
const toStorage = message => {
messages.push(message);
switch (message.method) {
case 'getStoreKey': {
const [key] = message.args;
return { storeName: 'swingset', storeSubkey: `fake:${key}` };
}
case 'get': {
const [key] = message.args;
return data.has(key) ? data.get(key) : null;
}
case 'children': {
const [key] = message.args;
const childEntries = getChildEntries(`${key}.`);
return [...childEntries.keys()];
}
case 'entries': {
const [key] = message.args;
const childEntries = getChildEntries(`${key}.`);
return [...childEntries.entries()].map(entry =>
entry[1] != null ? entry : [entry[0]],
);
}
case 'set':
case 'setWithoutNotify': {
trace('toStorage set', message);
/** @type {StorageEntry[]} */
const newEntries = message.args;
for (const [key, value] of newEntries) {
if (value != null) {
data.set(key, value);
} else {
data.delete(key);
const toStorage = Far(
'ToStorage',
/** @param {StorageMessage} message */
message => {
messages.push(message);
switch (message.method) {
case 'getStoreKey': {
const [key] = message.args;
return { storeName: 'swingset', storeSubkey: `fake:${key}` };
}
case 'get': {
const [key] = message.args;
return data.has(key) ? data.get(key) : null;
}
case 'children': {
const [key] = message.args;
const childEntries = getChildEntries(`${key}.`);
return [...childEntries.keys()];
}
case 'entries': {
const [key] = message.args;
const childEntries = getChildEntries(`${key}.`);
return [...childEntries.entries()].map(entry =>
entry[1] != null ? entry : [entry[0]],
);
}
case 'set':
case 'setWithoutNotify': {
trace('toStorage set', message);
/** @type {StorageEntry[]} */
const newEntries = message.args;
for (const [key, value] of newEntries) {
if (value != null) {
data.set(key, value);
} else {
data.delete(key);
}
}
break;
}
break;
}
case 'append': {
trace('toStorage append', message);
/** @type {StorageEntry[]} */
const newEntries = message.args;
for (const [key, value] of newEntries) {
value != null || Fail`attempt to append with no value`;
// In the absence of block boundaries, everything goes in a single StreamCell.
const oldVal = data.get(key);
let streamCell;
if (oldVal != null) {
try {
streamCell = JSON.parse(oldVal);
assert(isStreamCell(streamCell));
} catch (_err) {
streamCell = undefined;
case 'append': {
trace('toStorage append', message);
/** @type {StorageEntry[]} */
const newEntries = message.args;
for (const [key, value] of newEntries) {
value != null || Fail`attempt to append with no value`;
// In the absence of block boundaries, everything goes in a single StreamCell.
const oldVal = data.get(key);
let streamCell;
if (oldVal != null) {
try {
streamCell = JSON.parse(oldVal);
assert(isStreamCell(streamCell));
} catch (_err) {
streamCell = undefined;
}
}
if (streamCell === undefined) {
streamCell = {
blockHeight: '0',
values: oldVal != null ? [oldVal] : [],
};
}
streamCell.values.push(value);
data.set(key, JSON.stringify(streamCell));
}
if (streamCell === undefined) {
streamCell = {
blockHeight: '0',
values: oldVal != null ? [oldVal] : [],
};
}
streamCell.values.push(value);
data.set(key, JSON.stringify(streamCell));
break;
}
break;
case 'size':
// Intentionally incorrect because it counts non-child descendants,
// but nevertheless supports a "has children" test.
return [...data.keys()].filter(k =>
k.startsWith(`${message.args[0]}.`),
).length;
default:
throw Error(`unsupported method: ${message.method}`);
}
case 'size':
// Intentionally incorrect because it counts non-child descendants,
// but nevertheless supports a "has children" test.
return [...data.keys()].filter(k => k.startsWith(`${message.args[0]}.`))
.length;
default:
throw Error(`unsupported method: ${message.method}`);
}
},
);
const rootNode = makeChainStorageRoot(toStorage, rootPath, resolvedOptions);
/**
* Get the values at a sequence node
*
* @param {string} path
* @returns {string[]}
*/
const getValues = path => {
assert(resolvedOptions.sequence);
const nodeData = data.get(path);
assert(nodeData, `no data at path ${path}`);
const wrapper = JSON.parse(nodeData);
return wrapper.values;
};
const rootNode = makeChainStorageRoot(toStorage, rootPath, resolvedOptions);
return {

@@ -195,2 +225,3 @@ rootNode,

data: /** @type {Map<string, string>} */ (data),
getValues,
messages,

@@ -253,3 +284,5 @@ toStorage,

* @param {({ note: string } | { node: string; owner: string }) &
* ({ pattern: string; replacement: string } | {})} opts
* ({ pattern: string; replacement: string } | {}) & {
* showValue?: (v: string) => unknown;
* }} opts
*/

@@ -260,6 +293,15 @@ export const documentStorageSchema = async (t, storage, opts) => {

const getLast = (/** @type {string} */ cell) =>
JSON.parse(cell).values.at(-1) || assert.fail();
const { showValue = s => s } = opts;
/** @type {(d: Map<string, string>, k: string) => unknown} */
const getBodyDefault = (d, k) => showValue(getLast(NonNullish(d.get(k))));
const [keys, getBody] =
'keys' in storage
? [storage.keys(), (/** @type {string} */ k) => storage.getBody(k)]
: [storage.data.keys(), (/** @type {string} */ k) => storage.data.get(k)];
: [
storage.data.keys(),
(/** @type {string} */ k) => getBodyDefault(storage.data, k),
];

@@ -270,11 +312,18 @@ const { pattern, replacement } =

: { pattern: 'mockChainStorageRoot.', replacement: 'published.' };
const illustration = [...keys].sort().map(
const pruned = [...keys]
.sort()
.filter(
'node' in opts
? key =>
key
.replace(pattern, replacement)
.startsWith(`published.${opts.node}`)
: _entry => true,
);
const illustration = pruned.map(
/** @type {(k: string) => [string, unknown]} */
key => [key.replace(pattern, replacement), getBody(key)],
);
const pruned = illustration.filter(
'node' in opts
? ([key, _]) => key.startsWith(`published.${opts.node}`)
: _entry => true,
);

@@ -289,3 +338,3 @@ const note =

See also board marshalling conventions (_to appear_).`;
t.snapshot(pruned, note + boilerplate);
t.snapshot(illustration, note + boilerplate);
};

@@ -1,3 +0,6 @@

/** @file adapted from https://raw.githubusercontent.com/sindresorhus/type-fest/main/source/opaque.d.ts */
/** @file adapted from https://raw.githubusercontent.com/sindresorhus/type-fest/main/source/tagged.d.ts */
// different name to avoid confusion with pass-style "tagged"
export { Tagged as TypeTag };
declare const tag: unique symbol;

@@ -4,0 +7,0 @@

@@ -31,3 +31,3 @@ // @ts-check

* @param {MapStore} store
* @returns {object} tree of the contents of the storeÂ
* @returns {object} tree of the contents of the store
*/

@@ -34,0 +34,0 @@ export const inspectMapStore = store => {

@@ -1,6 +0,5 @@

/* eslint-disable max-classes-per-file */
import type { ERef, RemotableBrand } from '@endo/eventual-send';
import type { Primitive } from '@endo/pass-style';
import type { Callable } from './utils.js';
import type { Pattern } from '@endo/patterns';
import type { Callable } from './ses-utils.js';
/**

@@ -11,28 +10,17 @@ * A map corresponding with a total function such that `get(key)` is assumed to

export type TotalMap<K, V> = Omit<Map<K, V>, 'get'> & {
/** Returns the element associated with the specified key in the TotalMap. */
get: (key: K) => V;
/** Returns the element associated with the specified key in the TotalMap. */
get: (key: K) => V;
};
export type TotalMapFrom<M extends Map> =
M extends Map<infer K, infer V> ? TotalMap<K, V> : never;
export type TotalMapFrom<M extends Map<any, any>> = M extends Map<infer K, infer V> ? TotalMap<K, V> : never;
export declare class Callback<I extends (...args: any[]) => any> {
private iface: I;
public target: any;
public methodName?: PropertyKey;
public bound: unknown[];
public isSync: boolean;
private iface;
target: any;
methodName?: PropertyKey;
bound: unknown[];
isSync: boolean;
}
export declare class SyncCallback<
I extends (...args: unknown[]) => any,
> extends Callback<I> {
private syncIface: I;
public isSync: true;
export declare class SyncCallback<I extends (...args: unknown[]) => any> extends Callback<I> {
private syncIface;
isSync: true;
}
/**

@@ -54,11 +42,6 @@ Returns a boolean for whether the given type is primitive value or primitive type.

export type IsPrimitive<T> = [T] extends [Primitive] ? true : false;
/** Recursively extract the non-callable properties of T */
export type DataOnly<T> =
IsPrimitive<T> extends true
? T
: T extends Callable
? never
: { [P in keyof T as T[P] extends Callable ? never : P]: DataOnly<T[P]> };
export type DataOnly<T> = IsPrimitive<T> extends true ? T : T extends Callable ? never : {
[P in keyof T as T[P] extends Callable ? never : P]: DataOnly<T[P]>;
};
/**

@@ -69,20 +52,7 @@ * A type that doesn't assume its parameter is local, but is satisfied with both

*/
export type Remote<Primary, Local = DataOnly<Primary>> =
| Primary
| RemotableBrand<Local, Primary>;
// TODO: Add type tests for FarRef and Remote.
export type Remote<Primary, Local = DataOnly<Primary>> = Primary | RemotableBrand<Local, Primary>;
/**
* Potentially remote promises or settled references.
*/
export type FarRef<Primary, Local = DataOnly<Primary>> = ERef<
Remote<Primary, Local>
>;
/*
* Stop-gap until https://github.com/Agoric/agoric-sdk/issues/6160
* explictly specify the type that the Pattern will verify through a match.
*
* TODO move all this pattern typing stuff to @endo/patterns
*/
export type FarRef<Primary, Local = DataOnly<Primary>> = ERef<Remote<Primary, Local>>;
declare const validatedType: unique symbol;

@@ -92,8 +62,6 @@ /**

*/
export type TypedPattern<T> = Pattern & { [validatedType]?: T };
export declare type PatternType<TM extends TypedPattern<any>> =
TM extends TypedPattern<infer T> ? T : never;
// TODO make Endo's mustMatch do this
export type TypedPattern<T> = Pattern & {
[validatedType]?: T;
};
export declare type PatternType<TM extends TypedPattern<any>> = TM extends TypedPattern<infer T> ? T : never;
/**

@@ -107,6 +75,4 @@ * Returning normally indicates success. Match failure is indicated by

*/
export declare type MustMatch = <P extends Pattern>(
specimen: unknown,
pattern: P,
label?: string | number,
) => asserts specimen is P extends TypedPattern<any> ? PatternType<P> : unknown;
export declare type MustMatch = <P extends Pattern>(specimen: unknown, pattern: P, label?: string | number) => asserts specimen is P extends TypedPattern<any> ? PatternType<P> : unknown;
export {};
//# sourceMappingURL=types.d.ts.map

@@ -8,2 +8,3 @@ export namespace UpgradeDisconnectionShape {

export function isUpgradeDisconnection(reason: any): reason is UpgradeDisconnection;
export function isAbandonedError(reason: any): reason is Error;
/**

@@ -10,0 +11,0 @@ * An Error-like object for use as the rejection reason of promises abandoned by

@@ -48,3 +48,27 @@ // @ts-check

export const isUpgradeDisconnection = reason =>
isFrozen(reason) && matches(reason, UpgradeDisconnectionShape);
reason != null && // eslint-disable-line eqeqeq
isFrozen(reason) &&
matches(reason, UpgradeDisconnectionShape);
harden(isUpgradeDisconnection);
/**
* Returns whether a reason is a 'vat terminated' error generated when an object
* is abandoned by a vat during an upgrade.
*
* Normally we do not want to rely on the `message` of an error object, but this
* is a pragmatic solution to the current state of vat upgrade errors. In the
* future we'd prefer having an error with a cause referencing a disconnection
* object like for promise rejections. See
* https://github.com/Agoric/agoric-sdk/issues/9582
*
* @param {any} reason
* @returns {reason is Error}
*/
export const isAbandonedError = reason =>
reason != null && // eslint-disable-line eqeqeq
isFrozen(reason) &&
matches(reason, M.error()) &&
// We're not using a constant here since this special value is already
// sprinkled throughout the SDK
reason.message === 'vat terminated';
harden(isAbandonedError);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc