@agoric/wallet-backend 0.13.4-dev-00b01e2.0 → 0.13.4-dev-968b7a3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bundles/bundle-wallet-meta.js +121 -121
- package/bundles/bundle-wallet.js +1 -1
- package/deploy.js +2 -2
- package/package.json +13 -13
- package/src/findOrMakeInvitation.js +8 -11
- package/src/lib-dehydrate.js +13 -21
- package/src/lib-wallet.js +17 -25
- package/src/marshal-contexts.js +6 -4
package/deploy.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// FIXME: This is just hacked together for the legacy wallet.
|
|
4
4
|
|
|
5
5
|
import { E } from '@endo/eventual-send';
|
|
6
|
-
import {
|
|
6
|
+
import { Fail } from '@agoric/assert';
|
|
7
7
|
import path from 'path';
|
|
8
8
|
|
|
9
9
|
const filename = new URL(import.meta.url).pathname;
|
|
@@ -63,7 +63,7 @@ export default async function deployWallet(
|
|
|
63
63
|
issuers.map(async ([issuerPetname, issuer]) => {
|
|
64
64
|
const brand = await E(issuer).getBrand();
|
|
65
65
|
const brandMatches = E(brand).isMyIssuer(issuer);
|
|
66
|
-
|
|
66
|
+
brandMatches || Fail`issuer was using a brand which was not its own`;
|
|
67
67
|
brandToIssuer.set(brand, { issuerPetname, issuer });
|
|
68
68
|
}),
|
|
69
69
|
]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agoric/wallet-backend",
|
|
3
|
-
"version": "0.13.4-dev-
|
|
3
|
+
"version": "0.13.4-dev-968b7a3.0+968b7a3",
|
|
4
4
|
"description": "Wallet backend",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -14,23 +14,23 @@
|
|
|
14
14
|
"lint:eslint": "eslint ."
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@agoric/deploy-script-support": "0.9.5-dev-
|
|
18
|
-
"@agoric/vats": "0.13.1-dev-
|
|
17
|
+
"@agoric/deploy-script-support": "0.9.5-dev-968b7a3.0+968b7a3",
|
|
18
|
+
"@agoric/vats": "0.13.1-dev-968b7a3.0+968b7a3",
|
|
19
19
|
"@endo/bundle-source": "^2.4.2",
|
|
20
20
|
"@endo/init": "^0.5.52",
|
|
21
21
|
"ava": "^5.0.1"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@agoric/assert": "0.5.2-dev-
|
|
25
|
-
"@agoric/cache": "0.2.4-dev-
|
|
26
|
-
"@agoric/ertp": "0.15.4-dev-
|
|
27
|
-
"@agoric/inter-protocol": "0.13.2-dev-
|
|
28
|
-
"@agoric/internal": "0.2.2-dev-
|
|
24
|
+
"@agoric/assert": "0.5.2-dev-968b7a3.0+968b7a3",
|
|
25
|
+
"@agoric/cache": "0.2.4-dev-968b7a3.0+968b7a3",
|
|
26
|
+
"@agoric/ertp": "0.15.4-dev-968b7a3.0+968b7a3",
|
|
27
|
+
"@agoric/inter-protocol": "0.13.2-dev-968b7a3.0+968b7a3",
|
|
28
|
+
"@agoric/internal": "0.2.2-dev-968b7a3.0+968b7a3",
|
|
29
29
|
"@agoric/nat": "^4.1.0",
|
|
30
|
-
"@agoric/notifier": "0.5.2-dev-
|
|
31
|
-
"@agoric/store": "0.8.4-dev-
|
|
32
|
-
"@agoric/vat-data": "0.4.4-dev-
|
|
33
|
-
"@agoric/zoe": "0.25.4-dev-
|
|
30
|
+
"@agoric/notifier": "0.5.2-dev-968b7a3.0+968b7a3",
|
|
31
|
+
"@agoric/store": "0.8.4-dev-968b7a3.0+968b7a3",
|
|
32
|
+
"@agoric/vat-data": "0.4.4-dev-968b7a3.0+968b7a3",
|
|
33
|
+
"@agoric/zoe": "0.25.4-dev-968b7a3.0+968b7a3",
|
|
34
34
|
"@endo/eventual-send": "^0.16.8",
|
|
35
35
|
"@endo/marshal": "^0.8.1",
|
|
36
36
|
"@endo/promise-kit": "^0.2.52",
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"publishConfig": {
|
|
58
58
|
"access": "public"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "968b7a3fb5d54284ce9beef937624d751cb2f8d3"
|
|
61
61
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assert,
|
|
1
|
+
import { assert, Fail, q } from '@agoric/assert';
|
|
2
2
|
import { E } from '@endo/eventual-send';
|
|
3
3
|
import { passStyleOf } from '@endo/marshal';
|
|
4
4
|
import { AmountMath } from '@agoric/ertp';
|
|
@@ -8,14 +8,12 @@ export const makeId = (dappOrigin, rawId) => `${dappOrigin}#${rawId}`;
|
|
|
8
8
|
const assertFirstCapASCII = str => {
|
|
9
9
|
assert.typeof(str, 'string');
|
|
10
10
|
const firstCapASCII = /^[A-Z][a-zA-Z0-9_$]*$/;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
X`The string ${q(
|
|
11
|
+
firstCapASCII.test(str) ||
|
|
12
|
+
Fail`The string ${q(
|
|
14
13
|
str,
|
|
15
|
-
)} must be an ascii identifier starting with upper case
|
|
16
|
-
);
|
|
14
|
+
)} must be an ascii identifier starting with upper case.`;
|
|
17
15
|
(str !== 'NaN' && str !== 'Infinity') ||
|
|
18
|
-
|
|
16
|
+
Fail`keyword ${q(str)} must not be a number's name`;
|
|
19
17
|
};
|
|
20
18
|
|
|
21
19
|
/**
|
|
@@ -31,8 +29,7 @@ const findByBoardId = async (invitationPurseBalance, { board, boardId }) => {
|
|
|
31
29
|
const invitationHandle = await E(board).getValue(boardId);
|
|
32
30
|
const match = element => element.handle === invitationHandle;
|
|
33
31
|
const matchingValue = invitationPurseBalance.value.find(match);
|
|
34
|
-
matchingValue ||
|
|
35
|
-
assert.fail(X`Cannot find invitation corresponding to ${q(boardId)}`);
|
|
32
|
+
matchingValue || Fail`Cannot find invitation corresponding to ${q(boardId)}`;
|
|
36
33
|
|
|
37
34
|
return harden([matchingValue]);
|
|
38
35
|
};
|
|
@@ -53,7 +50,7 @@ const findByKeyValuePairs = async (invitationPurseBalance, kvs) => {
|
|
|
53
50
|
);
|
|
54
51
|
|
|
55
52
|
const matchingValue = invitationPurseBalance.value.find(matches);
|
|
56
|
-
|
|
53
|
+
matchingValue || Fail`Cannot find invitation corresponding to ${q(kvs)}`;
|
|
57
54
|
return harden([matchingValue]);
|
|
58
55
|
};
|
|
59
56
|
|
|
@@ -169,5 +166,5 @@ export const findOrMakeInvitation = async (
|
|
|
169
166
|
);
|
|
170
167
|
}
|
|
171
168
|
|
|
172
|
-
|
|
169
|
+
throw Fail`no invitation was found or made for this offer ${offer.id}`;
|
|
173
170
|
};
|
package/src/lib-dehydrate.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { makeMarshal, mapIterable } from '@endo/marshal';
|
|
4
4
|
import { makeLegacyMap, makeScalarMap } from '@agoric/store';
|
|
5
|
-
import { assert,
|
|
5
|
+
import { assert, Fail, q } from '@agoric/assert';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @typedef {string[]} Path
|
|
@@ -14,7 +14,7 @@ export const isPath = x => {
|
|
|
14
14
|
if (!Array.isArray(x)) {
|
|
15
15
|
return false;
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
x.length > 0 || Fail`Path ${q(x)} must not be empty`;
|
|
18
18
|
for (const name of x) {
|
|
19
19
|
if (typeof name !== 'string') {
|
|
20
20
|
return false;
|
|
@@ -49,9 +49,7 @@ export const makeDehydrator = (initialUnnamedCount = 0) => {
|
|
|
49
49
|
*/
|
|
50
50
|
const explode = data => {
|
|
51
51
|
data.startsWith(IMPLODE_PREFIX) ||
|
|
52
|
-
|
|
53
|
-
X`exploded string ${data} must start with ${q(IMPLODE_PREFIX)}`,
|
|
54
|
-
);
|
|
52
|
+
Fail`exploded string ${data} must start with ${q(IMPLODE_PREFIX)}`;
|
|
55
53
|
const strongname = JSON.parse(data.slice(IMPLODE_PREFIX.length));
|
|
56
54
|
if (!isPath(strongname)) {
|
|
57
55
|
return strongname;
|
|
@@ -79,7 +77,7 @@ export const makeDehydrator = (initialUnnamedCount = 0) => {
|
|
|
79
77
|
const { petnameToVal: petnameToRoot } = edgeMapping;
|
|
80
78
|
if (!petnameToRoot.has(path[0])) {
|
|
81
79
|
// Avoid asserting, which fills up the logs.
|
|
82
|
-
|
|
80
|
+
Fail`Edgename for ${q(path[0])} petname not found`;
|
|
83
81
|
}
|
|
84
82
|
const root = petnameToRoot.get(path[0]);
|
|
85
83
|
path[0] = root;
|
|
@@ -94,7 +92,7 @@ export const makeDehydrator = (initialUnnamedCount = 0) => {
|
|
|
94
92
|
* @returns {Mapping<T>}
|
|
95
93
|
*/
|
|
96
94
|
const makeMapping = (kind, { useLegacyMap = false } = {}) => {
|
|
97
|
-
|
|
95
|
+
typeof kind === 'string' || `kind ${kind} must be a string`;
|
|
98
96
|
const makeMap = useLegacyMap ? makeLegacyMap : makeScalarMap;
|
|
99
97
|
// These are actually either a LegacyMap or a MapStore depending on
|
|
100
98
|
// useLegacyMap. Fortunately, the LegacyMap type is approximately the
|
|
@@ -164,7 +162,7 @@ export const makeDehydrator = (initialUnnamedCount = 0) => {
|
|
|
164
162
|
* @param {any} val
|
|
165
163
|
*/
|
|
166
164
|
const addPath = (path, val) => {
|
|
167
|
-
|
|
165
|
+
isPath(path) || Fail`path ${q(path)} must be an array of strings`;
|
|
168
166
|
|
|
169
167
|
if (
|
|
170
168
|
!valToPetname.has(val) &&
|
|
@@ -206,9 +204,8 @@ export const makeDehydrator = (initialUnnamedCount = 0) => {
|
|
|
206
204
|
if (petnameToVal.has(petname) && petnameToVal.get(petname) === val) {
|
|
207
205
|
return;
|
|
208
206
|
}
|
|
209
|
-
!petnameToVal.has(petname) ||
|
|
210
|
-
|
|
211
|
-
assert(!valToPetname.has(val), X`val ${val} already has a petname`);
|
|
207
|
+
!petnameToVal.has(petname) || Fail`petname ${petname} is already in use`;
|
|
208
|
+
!valToPetname.has(val) || Fail`val ${val} already has a petname`;
|
|
212
209
|
petnameToVal.init(petname, val);
|
|
213
210
|
valToPetname.init(val, petname);
|
|
214
211
|
|
|
@@ -219,11 +216,8 @@ export const makeDehydrator = (initialUnnamedCount = 0) => {
|
|
|
219
216
|
|
|
220
217
|
const renamePetname = (petname, val) => {
|
|
221
218
|
valToPetname.has(val) ||
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
);
|
|
225
|
-
!petnameToVal.has(petname) ||
|
|
226
|
-
assert.fail(X`petname ${petname} is already in use`);
|
|
219
|
+
Fail`val ${val} has not been previously named, would you like to add it instead?`;
|
|
220
|
+
!petnameToVal.has(petname) || Fail`petname ${petname} is already in use`;
|
|
227
221
|
// Delete the old mappings.
|
|
228
222
|
const oldPetname = valToPetname.get(val);
|
|
229
223
|
petnameToVal.delete(oldPetname);
|
|
@@ -266,12 +260,10 @@ export const makeDehydrator = (initialUnnamedCount = 0) => {
|
|
|
266
260
|
};
|
|
267
261
|
|
|
268
262
|
const deletePetname = petname => {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
X`petname ${q(
|
|
263
|
+
petnameToVal.has(petname) ||
|
|
264
|
+
Fail`petname ${q(
|
|
272
265
|
petname,
|
|
273
|
-
)} has not been previously named, would you like to add it instead
|
|
274
|
-
);
|
|
266
|
+
)} has not been previously named, would you like to add it instead?`;
|
|
275
267
|
|
|
276
268
|
// Delete the mappings.
|
|
277
269
|
const val = petnameToVal.get(petname);
|
package/src/lib-wallet.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* and dapps.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import { assert,
|
|
14
|
+
import { assert, q, Fail } from '@agoric/assert';
|
|
15
15
|
import { makeScalarStoreCoordinator } from '@agoric/cache';
|
|
16
16
|
import { objectMap } from '@agoric/internal';
|
|
17
17
|
import { makeLegacyMap, makeScalarMap, makeScalarWeakMap } from '@agoric/store';
|
|
@@ -670,7 +670,7 @@ export function makeWalletRoot({
|
|
|
670
670
|
async ([keyword, { type, ...amount }]) => {
|
|
671
671
|
const purse = purseKeywordRecord[keyword];
|
|
672
672
|
purse !== undefined ||
|
|
673
|
-
|
|
673
|
+
Fail`purse was not found for keyword ${q(keyword)}`;
|
|
674
674
|
|
|
675
675
|
if (type === 'Attestation') {
|
|
676
676
|
const payment = await E(attMakerPK.promise).makeAttestation(amount);
|
|
@@ -886,13 +886,10 @@ export function makeWalletRoot({
|
|
|
886
886
|
const found = [...contactMapping.petnameToVal.entries()].find(
|
|
887
887
|
([_pn, { depositBoardId: dbid }]) => depositBoardId === dbid,
|
|
888
888
|
);
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
!found,
|
|
892
|
-
X`${q(found && found[0])} is already the petname for board ID ${q(
|
|
889
|
+
!found ||
|
|
890
|
+
Fail`${q(found && found[0])} is already the petname for board ID ${q(
|
|
893
891
|
depositBoardId,
|
|
894
|
-
)}
|
|
895
|
-
);
|
|
892
|
+
)}`;
|
|
896
893
|
|
|
897
894
|
const contact = harden(
|
|
898
895
|
addMeta({
|
|
@@ -1650,10 +1647,8 @@ export function makeWalletRoot({
|
|
|
1650
1647
|
/** @type {IssuerManager} */
|
|
1651
1648
|
const issuerManager = Far('IssuerManager', {
|
|
1652
1649
|
rename: async (petname, issuer) => {
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
`issuer has not been previously added`,
|
|
1656
|
-
);
|
|
1650
|
+
brandTable.hasByIssuer(issuer) ||
|
|
1651
|
+
Fail`issuer has not been previously added`;
|
|
1657
1652
|
const brandRecord = brandTable.getByIssuer(issuer);
|
|
1658
1653
|
brandMapping.renamePetname(petname, brandRecord.brand);
|
|
1659
1654
|
await updateAllState();
|
|
@@ -1712,7 +1707,7 @@ export function makeWalletRoot({
|
|
|
1712
1707
|
passStyleOf(offerResult) === 'copyRecord',
|
|
1713
1708
|
`offerResult must be a record to have a uiNotifier`,
|
|
1714
1709
|
);
|
|
1715
|
-
|
|
1710
|
+
offerResult.uiNotifier || Fail`offerResult does not have a uiNotifier`;
|
|
1716
1711
|
return offerResult.uiNotifier;
|
|
1717
1712
|
}
|
|
1718
1713
|
|
|
@@ -1735,11 +1730,9 @@ export function makeWalletRoot({
|
|
|
1735
1730
|
|
|
1736
1731
|
const { publicSubscribers } = offerResult;
|
|
1737
1732
|
publicSubscribers ||
|
|
1738
|
-
|
|
1739
|
-
X`offerResult ${offerResult} does not have publicSubscribers`,
|
|
1740
|
-
);
|
|
1733
|
+
Fail`offerResult ${offerResult} does not have publicSubscribers`;
|
|
1741
1734
|
passStyleOf(publicSubscribers) === 'copyRecord' ||
|
|
1742
|
-
|
|
1735
|
+
Fail`publicSubscribers ${publicSubscribers} must be a record`;
|
|
1743
1736
|
|
|
1744
1737
|
return publicSubscribers;
|
|
1745
1738
|
}
|
|
@@ -1805,13 +1798,10 @@ export function makeWalletRoot({
|
|
|
1805
1798
|
const idOnly =
|
|
1806
1799
|
(kind, lookup) =>
|
|
1807
1800
|
(...path) => {
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
1,
|
|
1811
|
-
X`${assert.quote(
|
|
1801
|
+
path.length === 1 ||
|
|
1802
|
+
Fail`${assert.quote(
|
|
1812
1803
|
kind,
|
|
1813
|
-
)} lookup must be called with a single offer ID, not ${path}
|
|
1814
|
-
);
|
|
1804
|
+
)} lookup must be called with a single offer ID, not ${path}`;
|
|
1815
1805
|
return lookup(path[0]);
|
|
1816
1806
|
};
|
|
1817
1807
|
makeLookup('offer', idOnly('offer', idToOffer.get));
|
|
@@ -1969,14 +1959,16 @@ export function makeWalletRoot({
|
|
|
1969
1959
|
return board;
|
|
1970
1960
|
},
|
|
1971
1961
|
getAgoricNames(...path) {
|
|
1972
|
-
|
|
1962
|
+
if (!agoricNames) {
|
|
1963
|
+
throw Fail`agoricNames was not supplied to the wallet maker`;
|
|
1964
|
+
}
|
|
1973
1965
|
return E(agoricNames).lookup(...path);
|
|
1974
1966
|
},
|
|
1975
1967
|
getNamesByAddress(...path) {
|
|
1976
1968
|
if (namesByAddress === undefined) {
|
|
1977
1969
|
// TypeScript confused about `||` control flow so use `if` instead
|
|
1978
1970
|
// https://github.com/microsoft/TypeScript/issues/50739
|
|
1979
|
-
|
|
1971
|
+
throw Fail`namesByAddress was not supplied to the wallet maker`;
|
|
1980
1972
|
}
|
|
1981
1973
|
return E(namesByAddress).lookup(...path);
|
|
1982
1974
|
},
|
package/src/marshal-contexts.js
CHANGED
|
@@ -3,7 +3,7 @@ import { makeScalarMap } from '@agoric/store';
|
|
|
3
3
|
import { Far, makeMarshal, Remotable } from '@endo/marshal';
|
|
4
4
|
import { HandledPromise } from '@endo/eventual-send'; // TODO: convince tsc this isn't needed
|
|
5
5
|
|
|
6
|
-
const {
|
|
6
|
+
const { Fail, quote: q } = assert;
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* For a value with a known id in the board, we can use
|
|
@@ -155,7 +155,7 @@ export const makeExportContext = () => {
|
|
|
155
155
|
return boardObjects.bySlot.get(slot);
|
|
156
156
|
}
|
|
157
157
|
const { kind, id } = parseWalletSlot(walletObjects, slot);
|
|
158
|
-
|
|
158
|
+
kind || Fail`bad slot kind: ${slot}`;
|
|
159
159
|
const val = walletObjects[kind].bySlot.get(id); // or throw
|
|
160
160
|
return val;
|
|
161
161
|
};
|
|
@@ -287,7 +287,7 @@ export const makeImportContext = (makePresence = defaultMakePresence) => {
|
|
|
287
287
|
* @param {string} iface
|
|
288
288
|
*/
|
|
289
289
|
fromBoard: (slot, iface) => {
|
|
290
|
-
|
|
290
|
+
isBoardId(slot) || Fail`bad board slot ${q(slot)}`;
|
|
291
291
|
return provideVal(boardObjects, slot, iface);
|
|
292
292
|
},
|
|
293
293
|
|
|
@@ -312,7 +312,9 @@ export const makeImportContext = (makePresence = defaultMakePresence) => {
|
|
|
312
312
|
/** @param {unknown} val */
|
|
313
313
|
fromMyWallet: val => {
|
|
314
314
|
const kind = findKey(walletObjects, k => walletObjects[k].byVal.has(val));
|
|
315
|
-
|
|
315
|
+
if (kind === undefined) {
|
|
316
|
+
throw Fail`cannot serialize unregistered ${val}`;
|
|
317
|
+
}
|
|
316
318
|
|
|
317
319
|
const id = walletObjects[kind].byVal.get(val);
|
|
318
320
|
return makeWalletSlot(walletObjects, kind, id);
|