From 9fc41b85902273b5bed377237b36316c7a762a7e Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Fri, 19 Jul 2024 15:04:10 -0700 Subject: [PATCH 1/2] BREAKING CHANGE: promote /vatsafe to top module --- packages/cosmic-proto/README.md | 24 ++----------- packages/cosmic-proto/package.json | 4 --- packages/cosmic-proto/src/index.ts | 5 ++- packages/cosmic-proto/src/vatsafe.ts | 2 -- packages/cosmic-proto/test/exports.test.js | 12 ++++--- packages/cosmic-proto/test/readme.test.js | 16 ++------- .../test/snapshots/exports.test.js.md | 32 ------------------ .../test/snapshots/exports.test.js.snap | Bin 1258 -> 856 bytes packages/cosmic-proto/test/vatsafe.test.js | 22 ------------ 9 files changed, 17 insertions(+), 100 deletions(-) delete mode 100644 packages/cosmic-proto/src/vatsafe.ts diff --git a/packages/cosmic-proto/README.md b/packages/cosmic-proto/README.md index 57da42b9d3e..e46015a25b1 100644 --- a/packages/cosmic-proto/README.md +++ b/packages/cosmic-proto/README.md @@ -27,21 +27,14 @@ npm install @agoric/cosmic-proto ## Usage ### RPC Clients -```js -import { agoric } from '@agoric/cosmic-proto'; - -const { createRPCQueryClient } = agoric.ClientFactory; -const client = await createRPCQueryClient({ rpcEndpoint: RPC_ENDPOINT }); - -const swingsetParams = await client.agoric.swingset.params() -``` +TODO #9200 ### Composing Messages -Import the `agoric` object from `@agoric/cosmic-proto`. +Import the `agoric` object from the Agoric bundle. ```js -import { agoric } from '@agoric/cosmic-proto'; +import { agoric } from '@agoric/cosmic-proto/agoric/bundle.js'; const { installBundle, @@ -54,18 +47,7 @@ const { Here are the docs on [creating signers](https://github.com/cosmology-tech/cosmos-kit/tree/main/packages/react#signing-clients) in cosmos-kit that can be used with Keplr and other wallets. -### Initializing the Stargate Client - -Use `getSigningAgoricClient` to get your `SigningStargateClient`, with the proto/amino messages full-loaded. No need to manually add amino types, just require and initialize the client: -```js -import { getSigningAgoricClient } from '@agoric/cosmic-proto'; - -const stargateClient = await getSigningAgoricClient({ - rpcEndpoint, - signer // OfflineSigner -}); -``` ### Creating Signers To broadcast messages, you can create signers with a variety of options: diff --git a/packages/cosmic-proto/package.json b/packages/cosmic-proto/package.json index 1a492ea4bef..892aa9ef6ee 100644 --- a/packages/cosmic-proto/package.json +++ b/packages/cosmic-proto/package.json @@ -19,10 +19,6 @@ "types": "./dist/index.d.ts", "default": "./dist/index.js" }, - "./vatsafe": { - "types": "./dist/vatsafe.d.ts", - "default": "./dist/vatsafe.js" - }, "./package.json": "./package.json", "./agoric/*.js": { "types": "./dist/codegen/agoric/*.d.ts", diff --git a/packages/cosmic-proto/src/index.ts b/packages/cosmic-proto/src/index.ts index 8643097653e..c3a5f798955 100644 --- a/packages/cosmic-proto/src/index.ts +++ b/packages/cosmic-proto/src/index.ts @@ -1,3 +1,6 @@ -export * from './codegen/index.js'; +// Do not export codegen/index.js because it entrains multiple megabytes of module imports. +// Instead we have the top level be relatively conservative, just things that are safe to import into a vat. +// This can include all the types because those are free (never included in a JS bundle). +export * from './codegen/json-safe.js'; export * from './helpers.js'; diff --git a/packages/cosmic-proto/src/vatsafe.ts b/packages/cosmic-proto/src/vatsafe.ts deleted file mode 100644 index 780f0c00ce3..00000000000 --- a/packages/cosmic-proto/src/vatsafe.ts +++ /dev/null @@ -1,2 +0,0 @@ -/** @file top level export (similar to index.js) but only with modules that can load from within a vat */ -export * from './helpers.js'; diff --git a/packages/cosmic-proto/test/exports.test.js b/packages/cosmic-proto/test/exports.test.js index 88f31c13f05..d5e9ba3db8d 100644 --- a/packages/cosmic-proto/test/exports.test.js +++ b/packages/cosmic-proto/test/exports.test.js @@ -1,10 +1,14 @@ -// @ts-check /* eslint-disable import/no-extraneous-dependencies -- requiring the package itself to check exports map */ +// @ts-check + import test from 'ava'; import '@endo/init'; import * as index from '@agoric/cosmic-proto'; +import { agoric } from '@agoric/cosmic-proto/agoric/bundle.js'; +import { cosmos } from '@agoric/cosmic-proto/cosmos/bundle.js'; +import { ibc } from '@agoric/cosmic-proto/ibc/bundle.js'; import * as swingsetMsgs from '@agoric/cosmic-proto/swingset/msgs.js'; import * as swingsetQuery from '@agoric/cosmic-proto/swingset/query.js'; import * as vstorageQuery from '@agoric/cosmic-proto/vstorage/query.js'; @@ -26,13 +30,13 @@ test('vstorage/query', t => { }); test('agoric', t => { - t.snapshot(Object.keys(index.agoric).sort()); + t.snapshot(Object.keys(agoric).sort()); }); test('cosmos', t => { - t.snapshot(Object.keys(index.cosmos).sort()); + t.snapshot(Object.keys(cosmos).sort()); }); test('ibc', t => { - t.snapshot(Object.keys(index.ibc).sort()); + t.snapshot(Object.keys(ibc).sort()); }); diff --git a/packages/cosmic-proto/test/readme.test.js b/packages/cosmic-proto/test/readme.test.js index 945afa643cc..83dfdf35b0c 100644 --- a/packages/cosmic-proto/test/readme.test.js +++ b/packages/cosmic-proto/test/readme.test.js @@ -1,21 +1,9 @@ // @ts-check /** @file snippets from the README */ -/* eslint-disable import/no-extraneous-dependencies -- requiring the package itself to check exports map */ -import test from 'ava'; - -import { agoric } from '../dist/index.js'; - -const RPC_ENDPOINT = ''; -// Skip because we don't have a real endpoint, still tests the types -test.skip('RPC Clients', async t => { - // @ts-expect-error - const { createRPCQueryClient } = agoric.ClientFactory; - const client = await createRPCQueryClient({ rpcEndpoint: RPC_ENDPOINT }); +import test from 'ava'; - const swingsetParams = await client.agoric.swingset.params(); - t.truthy(swingsetParams); -}); +import { agoric } from '../dist/codegen/agoric/bundle.js'; test.failing('Composing Messages', t => { // @ts-expect-error diff --git a/packages/cosmic-proto/test/snapshots/exports.test.js.md b/packages/cosmic-proto/test/snapshots/exports.test.js.md index 5241414b882..8faf119bf32 100644 --- a/packages/cosmic-proto/test/snapshots/exports.test.js.md +++ b/packages/cosmic-proto/test/snapshots/exports.test.js.md @@ -9,41 +9,9 @@ Generated by [AVA](https://avajs.dev). > Snapshot 1 [ - 'BinaryReader', - 'BinaryWriter', - 'WireType', - 'agoric', - 'amino', - 'cosmos', - 'cosmos_proto', - 'gogoproto', - 'google', - 'ibc', - 'icq', - 'ics23', - 'int64FromString', - 'int64Length', - 'int64ToString', - 'readInt32', - 'readUInt32', - 'tendermint', 'toRequestQueryJson', 'typeUrlToGrpcPath', 'typedJson', - 'uInt64ToString', - 'utf8Length', - 'utf8Read', - 'utf8Write', - 'varint32read', - 'varint32write', - 'varint64read', - 'varint64write', - 'writeByte', - 'writeFixed32', - 'writeVarint32', - 'writeVarint64', - 'zzDecode', - 'zzEncode', ] ## swingset/msgs diff --git a/packages/cosmic-proto/test/snapshots/exports.test.js.snap b/packages/cosmic-proto/test/snapshots/exports.test.js.snap index 5594cf1f2c40562aaa3562c8bc1dca76cc58fe87..306b4ec09e859aeafddd9e5046890ed184657047 100644 GIT binary patch literal 856 zcmV-e1E>5!RzV(`oaSMvt*({ z%JW*&9wF{qygPm_sJ}NZ9{%di0LD!)0WcJ<>6e@lv=>zU6Y5UIuUlz#4!z0KNeD1z;Be zjuPM!0qzmt4cR8YsbYSOrim7q;0e=7rU~^$A4%k-!ijk`M z=WT))VJ)5^=N^0)gPHKg>1a;2}F1aKAr2k;cY2LRsz{MoLRC%jhP z=-@MvX2zsF?bUjAfEiKcO{ht^XsNYAq^!_$gV2Z~Z=PwHYT7BDsXX{N#|*kmj8&RO zY-cWS0eA-BsRirK4od4MHPqrc|4YP%}A7=iUM}!spBeHsny5 z%|?zGaJfPwrFq~_)89FT)dc`c0B!>4r5fJ?_?)Wzuf|GIV@Yu4&(o^AA)c#p(xP(J zlT%7~EAU)QCqe~O1Z~Rw`B8P9<{MADL|c literal 1258 zcmVc?E|m)K+6Ya$;dP*pH+&s z39;X5wHnA6$Ri*Vm?b655f7w1O(xE9K~?)Aqajm0kdPd@uDI!=C5u+qxngVWgjvM1 z$Ow(3;(?9(HeRL;E~E{Y9X*h`A+?Q z<8@cmSU(tS+u*pXln46s85^Fk;TjiaVSY);#wDY;h%8~!62?1(7nq35rUegKaIyog z$-%QV_dtr#a9Nl$r!6#Pp|KRYJb+C*%rFr$)!@QdY{p_UMqXswO{UF@O{Urxv=o*z zYdO=Vov_O)UX#zOBv_^W!slFNDJ9IFK5U^w&E;Vab)T!QX*Ql5)Z>U7pcG3-&mu?N zg(=b*I}06iL(!s&r$VUA!Q)P1i(bnfzCU+(VLp5KMDFmy{J`M{Tv46yxpp5q>GF1< zCBDPLeuo}(c{}KpUS$@3Xc)XOZ{dfXO1ry@ERdnQ^;8BqFH)puSPgxRi%2u`L_sXTa{2)Qg9` zuQkqLy-2nSZd#6%Y$gT!^s|eRTlz+l&Z}S8`zqSdt;`C0mDe=mF5Ao~me06k_}W&i*H diff --git a/packages/cosmic-proto/test/vatsafe.test.js b/packages/cosmic-proto/test/vatsafe.test.js index db0d5175951..a184176e27d 100644 --- a/packages/cosmic-proto/test/vatsafe.test.js +++ b/packages/cosmic-proto/test/vatsafe.test.js @@ -1,31 +1,9 @@ // @ts-check /* eslint-disable import/no-extraneous-dependencies -- requiring the package itself to check exports map */ import test from '@endo/ses-ava/prepare-endo.js'; -import { cosmos } from '@agoric/cosmic-proto'; import { MsgDelegate } from '@agoric/cosmic-proto/cosmos/staking/v1beta1/tx.js'; -// @ts-expect-error -cosmos.staking.v1beta1.MsgDelegate.missing; -// @ts-expect-error -MsgDelegate.missing; - -test('imports', t => { - t.is(MsgDelegate, cosmos.staking.v1beta1.MsgDelegate); - - t.deepEqual(cosmos.staking.v1beta1.MsgDelegate.fromPartial({}), { - amount: undefined, - delegatorAddress: '', - validatorAddress: '', - }); - - t.deepEqual(MsgDelegate.fromPartial({}), { - amount: undefined, - delegatorAddress: '', - validatorAddress: '', - }); -}); - test('proto encoding', t => { const contents = { delegatorAddress: From 7dd34e323ce283b9f4785182aabcbfceb406fd0f Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Fri, 19 Jul 2024 15:04:36 -0700 Subject: [PATCH 2/2] refactor: use newly safe cosmic-proto top level --- packages/orchestration/src/exos/local-orchestration-account.js | 2 +- packages/vats/src/proposals/localchain-test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/orchestration/src/exos/local-orchestration-account.js b/packages/orchestration/src/exos/local-orchestration-account.js index c6f729bcbbb..707c9619d74 100644 --- a/packages/orchestration/src/exos/local-orchestration-account.js +++ b/packages/orchestration/src/exos/local-orchestration-account.js @@ -1,5 +1,5 @@ /** @file Use-object for the owner of a localchain account */ -import { typedJson } from '@agoric/cosmic-proto/vatsafe'; +import { typedJson } from '@agoric/cosmic-proto'; import { AmountShape, PaymentShape } from '@agoric/ertp'; import { makeTracer } from '@agoric/internal'; import { Shape as NetworkShape } from '@agoric/network'; diff --git a/packages/vats/src/proposals/localchain-test.js b/packages/vats/src/proposals/localchain-test.js index 8d0de02bb5f..fcaf7751a56 100644 --- a/packages/vats/src/proposals/localchain-test.js +++ b/packages/vats/src/proposals/localchain-test.js @@ -1,6 +1,6 @@ // @ts-check import { heapVowE as E } from '@agoric/vow/vat.js'; -import { typedJson } from '@agoric/cosmic-proto/vatsafe'; +import { typedJson } from '@agoric/cosmic-proto'; /** * @param {BootstrapPowers & {