@agoric/wallet-backend 0.13.5 → 0.13.6-dev-d32a66a.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-js-meta.json +582 -0
- package/bundles/bundle-wallet.js +1 -1
- package/deploy.js +2 -2
- package/jsconfig.json +1 -15
- package/package.json +22 -22
- package/scripts/build-bundles.js +1 -1
- package/src/findOrMakeInvitation.js +10 -13
- package/src/internal-types.js +6 -4
- package/src/issuerTable.js +5 -5
- package/src/lib-dehydrate.js +24 -31
- package/src/lib-wallet.js +85 -210
- package/src/types.js +2 -2
- package/src/wallet.js +4 -8
- package/test/test-getPursesNotifier.js +15 -16
- package/test/test-lib-dehydrate.js +10 -10
- package/test/test-lib-wallet.js +38 -247
- package/test/test-middleware.js +7 -15
- package/bundles/bundle-wallet-meta.js +0 -490
- package/src/marshal-contexts.js +0 -387
- package/test/attestationExample.js +0 -65
- package/test/test-wallet-marshal.js +0 -184
package/src/lib-wallet.js
CHANGED
|
@@ -11,34 +11,39 @@
|
|
|
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
|
-
import { objectMap } from '@agoric/internal';
|
|
17
|
-
import {
|
|
16
|
+
import { objectMap, WalletName } from '@agoric/internal';
|
|
17
|
+
import { slotStringUnserialize } from '@agoric/internal/src/storage-test-utils.js';
|
|
18
|
+
import {
|
|
19
|
+
makeLegacyMap,
|
|
20
|
+
makeScalarMapStore,
|
|
21
|
+
makeScalarWeakMapStore,
|
|
22
|
+
} from '@agoric/store';
|
|
18
23
|
import { makeScalarBigMapStore } from '@agoric/vat-data';
|
|
19
24
|
import { AmountMath } from '@agoric/ertp';
|
|
20
25
|
import { E } from '@endo/eventual-send';
|
|
21
26
|
|
|
22
|
-
import {
|
|
23
|
-
import { Nat } from '@
|
|
27
|
+
import { passStyleOf, Far, mapIterable } from '@endo/marshal';
|
|
28
|
+
import { Nat } from '@endo/nat';
|
|
24
29
|
import {
|
|
25
30
|
makeNotifierFromSubscriber,
|
|
26
31
|
makeNotifierKit,
|
|
27
32
|
observeIteration,
|
|
28
33
|
observeNotifier,
|
|
34
|
+
subscribeEach,
|
|
29
35
|
} from '@agoric/notifier';
|
|
30
36
|
import { makePromiseKit } from '@endo/promise-kit';
|
|
31
37
|
|
|
38
|
+
import { makeExportContext } from '@agoric/smart-wallet/src/marshal-contexts.js';
|
|
32
39
|
import { makeIssuerTable } from './issuerTable.js';
|
|
33
40
|
import { makeDehydrator } from './lib-dehydrate.js';
|
|
34
41
|
import { makeId, findOrMakeInvitation } from './findOrMakeInvitation.js';
|
|
35
42
|
import { bigintStringify } from './bigintStringify.js';
|
|
36
43
|
import { makePaymentActions } from './actions.js';
|
|
37
|
-
import { makeExportContext } from './marshal-contexts.js';
|
|
38
44
|
|
|
39
45
|
import '@agoric/store/exported.js';
|
|
40
46
|
import '@agoric/zoe/exported.js';
|
|
41
|
-
import '@agoric/inter-protocol/exported.js';
|
|
42
47
|
|
|
43
48
|
import './internal-types.js';
|
|
44
49
|
import './types.js';
|
|
@@ -59,16 +64,16 @@ const cmp = (a, b) => {
|
|
|
59
64
|
/**
|
|
60
65
|
* @param {{
|
|
61
66
|
* agoricNames?: ERef<NameHub>
|
|
62
|
-
* board: ERef<Board>
|
|
67
|
+
* board: ERef<import('@agoric/vats').Board>
|
|
63
68
|
* dateNow?: () => number,
|
|
64
69
|
* inboxStateChangeHandler?: (state: any) => void,
|
|
65
|
-
* myAddressNameAdmin: ERef<MyAddressNameAdmin>
|
|
70
|
+
* myAddressNameAdmin: ERef<import('@agoric/vats').MyAddressNameAdmin>
|
|
66
71
|
* namesByAddress?: ERef<NameHub>
|
|
67
72
|
* pursesStateChangeHandler?: (state: any) => void,
|
|
68
73
|
* zoe: ERef<ZoeService>,
|
|
69
74
|
* }} opt
|
|
70
75
|
*
|
|
71
|
-
* @typedef {import('@agoric/vats
|
|
76
|
+
* @typedef {import('@agoric/vats').NameHub} NameHub
|
|
72
77
|
*/
|
|
73
78
|
export function makeWalletRoot({
|
|
74
79
|
zoe,
|
|
@@ -136,8 +141,8 @@ export function makeWalletRoot({
|
|
|
136
141
|
const installationMapping = makeMapping('installation');
|
|
137
142
|
|
|
138
143
|
const brandTable = makeIssuerTable();
|
|
139
|
-
/** @type {
|
|
140
|
-
const issuerToBoardId =
|
|
144
|
+
/** @type {WeakMapStore<Issuer, string>} */
|
|
145
|
+
const issuerToBoardId = makeScalarWeakMapStore('issuer');
|
|
141
146
|
|
|
142
147
|
// Idempotently initialize the issuer's synchronous boardId mapping.
|
|
143
148
|
const initIssuerToBoardId = async (issuer, brand) => {
|
|
@@ -166,22 +171,23 @@ export function makeWalletRoot({
|
|
|
166
171
|
return issuerBoardId;
|
|
167
172
|
};
|
|
168
173
|
|
|
169
|
-
/** @type {
|
|
170
|
-
const purseToBrand =
|
|
171
|
-
/** @type {
|
|
172
|
-
const brandToDepositFacetId =
|
|
173
|
-
/** @type {
|
|
174
|
-
const brandToAutoDepositPurse =
|
|
174
|
+
/** @type {WeakMapStore<Purse, Brand>} */
|
|
175
|
+
const purseToBrand = makeScalarWeakMapStore('purse');
|
|
176
|
+
/** @type {MapStore<Brand, string>} */
|
|
177
|
+
const brandToDepositFacetId = makeScalarMapStore('brand');
|
|
178
|
+
/** @type {MapStore<Brand, Purse>} */
|
|
179
|
+
const brandToAutoDepositPurse = makeScalarMapStore('brand');
|
|
175
180
|
|
|
176
181
|
// Offers that the wallet knows about (the inbox).
|
|
177
|
-
|
|
178
|
-
const
|
|
182
|
+
/** @type {MapStore<string, any>} */
|
|
183
|
+
const idToOffer = makeScalarMapStore('offerId');
|
|
179
184
|
/** @type {LegacyMap<string, PromiseRecord<any>>} */
|
|
180
185
|
// Legacy because promise kits are not passables
|
|
181
186
|
const idToOfferResultPromiseKit = makeLegacyMap('id');
|
|
182
187
|
|
|
183
|
-
/** @type {
|
|
184
|
-
const invitationHandleToOfferResult =
|
|
188
|
+
/** @type {WeakMapStore<Handle<'invitation'>, any>} */
|
|
189
|
+
const invitationHandleToOfferResult =
|
|
190
|
+
makeScalarWeakMapStore('invitationHandle');
|
|
185
191
|
|
|
186
192
|
// Compiled offers (all ready to execute).
|
|
187
193
|
const idToCompiledOfferP = new Map();
|
|
@@ -223,18 +229,10 @@ export function makeWalletRoot({
|
|
|
223
229
|
return getSortedValues(inboxState);
|
|
224
230
|
}
|
|
225
231
|
|
|
226
|
-
const noOp = () => {};
|
|
227
|
-
const identitySlotToValFn = (slot, _) => slot;
|
|
228
|
-
|
|
229
232
|
// Instead of { body, slots }, fill the slots. This is useful for
|
|
230
233
|
// display but not for data processing, since the special identifier
|
|
231
234
|
// @qclass is lost.
|
|
232
|
-
const
|
|
233
|
-
marshalName: 'wallet',
|
|
234
|
-
// TODO Temporary hack.
|
|
235
|
-
// See https://github.com/Agoric/agoric-sdk/issues/2780
|
|
236
|
-
errorIdNum: 40000,
|
|
237
|
-
});
|
|
235
|
+
const fillInSlots = slotStringUnserialize;
|
|
238
236
|
|
|
239
237
|
/** @type {NotifierRecord<OfferState[]>} */
|
|
240
238
|
const { notifier: offersNotifier, updater: offersUpdater } = makeNotifierKit(
|
|
@@ -474,7 +472,7 @@ export function makeWalletRoot({
|
|
|
474
472
|
return;
|
|
475
473
|
case 'accept':
|
|
476
474
|
assert(idToOfferResultPromiseKit.has(id));
|
|
477
|
-
void idToOfferResultPromiseKit.get(id).promise
|
|
475
|
+
void E.when(idToOfferResultPromiseKit.get(id).promise, result => {
|
|
478
476
|
const style = passStyleOf(result);
|
|
479
477
|
const active =
|
|
480
478
|
style === 'remotable' ||
|
|
@@ -572,27 +570,20 @@ export function makeWalletRoot({
|
|
|
572
570
|
await updateAllInboxState();
|
|
573
571
|
}
|
|
574
572
|
|
|
575
|
-
// handle the update, which has already resolved to a record.
|
|
576
|
-
//
|
|
573
|
+
// handle the update, which has already resolved to a record. The update means
|
|
574
|
+
// the offer is 'done'.
|
|
577
575
|
function updateOrResubscribe(id, seat, update) {
|
|
578
576
|
const { updateCount } = update;
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
idToSeat.delete(id);
|
|
577
|
+
assert(updateCount === undefined);
|
|
578
|
+
idToSeat.delete(id);
|
|
582
579
|
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
idToNotifierP.delete(id);
|
|
591
|
-
} else {
|
|
592
|
-
E(idToNotifierP.get(id))
|
|
593
|
-
.getUpdateSince(updateCount)
|
|
594
|
-
.then(nextUpdate => updateOrResubscribe(id, seat, nextUpdate));
|
|
595
|
-
}
|
|
580
|
+
const offer = idToOffer.get(id);
|
|
581
|
+
const completedOffer = addMeta({
|
|
582
|
+
...offer,
|
|
583
|
+
status: 'complete',
|
|
584
|
+
});
|
|
585
|
+
idToOffer.set(id, completedOffer);
|
|
586
|
+
updateInboxState(id, completedOffer);
|
|
596
587
|
}
|
|
597
588
|
|
|
598
589
|
/**
|
|
@@ -601,51 +592,12 @@ export function makeWalletRoot({
|
|
|
601
592
|
* @param {string} id
|
|
602
593
|
* @param {ERef<UserSeat>} seat
|
|
603
594
|
*/
|
|
604
|
-
async function
|
|
605
|
-
E(seat)
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
// See https://github.com/Agoric/agoric-sdk/issues/5834
|
|
609
|
-
.getAllocationNotifierJig()
|
|
610
|
-
.then(offerNotifierP => {
|
|
611
|
-
if (!idToNotifierP.has(id)) {
|
|
612
|
-
idToNotifierP.init(id, offerNotifierP);
|
|
613
|
-
}
|
|
614
|
-
E(offerNotifierP)
|
|
615
|
-
.getUpdateSince()
|
|
616
|
-
.then(update => updateOrResubscribe(id, seat, update));
|
|
617
|
-
});
|
|
595
|
+
async function subscribeToUpdates(id, seat) {
|
|
596
|
+
E(E(seat).getExitSubscriber())
|
|
597
|
+
.subscribeAfter()
|
|
598
|
+
.then(update => updateOrResubscribe(id, seat, update));
|
|
618
599
|
}
|
|
619
600
|
|
|
620
|
-
/**
|
|
621
|
-
* @param {() => ( Promise | undefined )} get - The function whose return value
|
|
622
|
-
* to memoize.
|
|
623
|
-
*/
|
|
624
|
-
const makeMemoizedGetter = get => {
|
|
625
|
-
let pk;
|
|
626
|
-
const doGet = () => pk.resolve(get());
|
|
627
|
-
|
|
628
|
-
return () => {
|
|
629
|
-
if (pk === undefined) {
|
|
630
|
-
pk = makePromiseKit();
|
|
631
|
-
doGet();
|
|
632
|
-
}
|
|
633
|
-
return pk.promise;
|
|
634
|
-
};
|
|
635
|
-
};
|
|
636
|
-
|
|
637
|
-
const getAttIssuer = makeMemoizedGetter(() =>
|
|
638
|
-
E(agoricNames)?.lookup('issuer', 'Attestation'),
|
|
639
|
-
);
|
|
640
|
-
|
|
641
|
-
/** @type import('@endo/promise-kit').PromiseKit<AttestationTool> */
|
|
642
|
-
const attMakerPK = makePromiseKit();
|
|
643
|
-
|
|
644
|
-
const { getAccountState } = E(attMakerPK.promise);
|
|
645
|
-
|
|
646
|
-
const makeAttestationAmount = async bldAmount =>
|
|
647
|
-
E(attMakerPK.promise).wrapLienedAmount(bldAmount);
|
|
648
|
-
|
|
649
601
|
async function executeOffer(compiledOfferP) {
|
|
650
602
|
// =====================
|
|
651
603
|
// === AWAITING TURN ===
|
|
@@ -661,29 +613,13 @@ export function makeWalletRoot({
|
|
|
661
613
|
/** @type {Map<Payment, Purse>} */
|
|
662
614
|
const paymentToPurse = new Map();
|
|
663
615
|
|
|
664
|
-
// Track which gives/wants are attestations.
|
|
665
|
-
const keywordToAttestation = new Map();
|
|
666
|
-
|
|
667
616
|
// We now have everything we need to provide Zoe, so do the actual withdrawals.
|
|
668
617
|
// Payments are made for the keywords in proposal.give.
|
|
669
618
|
const keywordPaymentPs = Object.entries(proposal.give || harden({})).map(
|
|
670
|
-
async ([keyword,
|
|
619
|
+
async ([keyword, amount]) => {
|
|
671
620
|
const purse = purseKeywordRecord[keyword];
|
|
672
621
|
purse !== undefined ||
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
if (type === 'Attestation') {
|
|
676
|
-
const payment = await E(attMakerPK.promise).makeAttestation(amount);
|
|
677
|
-
|
|
678
|
-
const attestationIssuer = await getAttIssuer();
|
|
679
|
-
|
|
680
|
-
keywordToAttestation.set(
|
|
681
|
-
keyword,
|
|
682
|
-
await E(attestationIssuer).getAmountOf(payment),
|
|
683
|
-
);
|
|
684
|
-
|
|
685
|
-
return [keyword, payment];
|
|
686
|
-
}
|
|
622
|
+
Fail`purse was not found for keyword ${q(keyword)}`;
|
|
687
623
|
|
|
688
624
|
const payment = await E(purse).withdraw(amount);
|
|
689
625
|
paymentToPurse.set(payment, purse);
|
|
@@ -691,30 +627,6 @@ export function makeWalletRoot({
|
|
|
691
627
|
},
|
|
692
628
|
);
|
|
693
629
|
|
|
694
|
-
// Get Attestation-branded amounts for Attestastation "wants".
|
|
695
|
-
await Promise.all(
|
|
696
|
-
Object.entries(proposal.want || harden({})).map(
|
|
697
|
-
async ([keyword, { type, ...amount }]) => {
|
|
698
|
-
if (type === 'Attestation') {
|
|
699
|
-
const attestationAmount = await makeAttestationAmount(amount);
|
|
700
|
-
keywordToAttestation.set(keyword, attestationAmount);
|
|
701
|
-
}
|
|
702
|
-
},
|
|
703
|
-
),
|
|
704
|
-
);
|
|
705
|
-
|
|
706
|
-
const depositAttestation = async payoutP => {
|
|
707
|
-
const [issuer, payout] = await Promise.all([getAttIssuer(), payoutP]);
|
|
708
|
-
|
|
709
|
-
const amount = await E(issuer).getAmountOf(payout);
|
|
710
|
-
const invitation = await E(attMakerPK.promise).makeReturnAttInvitation();
|
|
711
|
-
const depositProposal = harden({ give: { Attestation: amount } });
|
|
712
|
-
const payments = harden({ Attestation: payout });
|
|
713
|
-
|
|
714
|
-
const userSeat = E(zoe).offer(invitation, depositProposal, payments);
|
|
715
|
-
await E(userSeat).getOfferResult();
|
|
716
|
-
};
|
|
717
|
-
|
|
718
630
|
// Try reclaiming any of our payments that we successfully withdrew, but
|
|
719
631
|
// were left unclaimed.
|
|
720
632
|
const tryReclaimingWithdrawnPayments = () =>
|
|
@@ -724,11 +636,7 @@ export function makeWalletRoot({
|
|
|
724
636
|
keywordPaymentPs.map(async keywordPaymentP => {
|
|
725
637
|
// Wait for the withdrawal to complete. This protects against a race
|
|
726
638
|
// when updating paymentToPurse.
|
|
727
|
-
const [
|
|
728
|
-
|
|
729
|
-
if (keywordToAttestation.has(keyword)) {
|
|
730
|
-
return depositAttestation(payment);
|
|
731
|
-
}
|
|
639
|
+
const [_keyword, payment] = await keywordPaymentP;
|
|
732
640
|
|
|
733
641
|
// Find out where it came from.
|
|
734
642
|
const purse = paymentToPurse.get(payment);
|
|
@@ -764,27 +672,6 @@ export function makeWalletRoot({
|
|
|
764
672
|
|
|
765
673
|
const paymentKeywordRecord = harden(Object.fromEntries(paymentKeywords));
|
|
766
674
|
|
|
767
|
-
// Convert gives'/wants' BLD amounts to Attestation amounts for
|
|
768
|
-
// Attestations.
|
|
769
|
-
const convertToAttestationAmounts = ([keyword, { type, ...amount }]) => {
|
|
770
|
-
if (type === 'Attestation') {
|
|
771
|
-
amount = keywordToAttestation.get(keyword);
|
|
772
|
-
}
|
|
773
|
-
return [keyword, amount];
|
|
774
|
-
};
|
|
775
|
-
|
|
776
|
-
if (proposal.give) {
|
|
777
|
-
proposal.give = Object.fromEntries(
|
|
778
|
-
Object.entries(proposal.give).map(convertToAttestationAmounts),
|
|
779
|
-
);
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
if (proposal.want) {
|
|
783
|
-
proposal.want = Object.fromEntries(
|
|
784
|
-
Object.entries(proposal.want).map(convertToAttestationAmounts),
|
|
785
|
-
);
|
|
786
|
-
}
|
|
787
|
-
|
|
788
675
|
const seat = E(zoe).offer(
|
|
789
676
|
inviteP,
|
|
790
677
|
harden(proposal),
|
|
@@ -802,10 +689,6 @@ export function makeWalletRoot({
|
|
|
802
689
|
.then(payoutObj => {
|
|
803
690
|
return Promise.all(
|
|
804
691
|
Object.entries(payoutObj).map(([keyword, payoutP]) => {
|
|
805
|
-
if (keywordToAttestation.has(keyword)) {
|
|
806
|
-
return depositAttestation(payoutP);
|
|
807
|
-
}
|
|
808
|
-
|
|
809
692
|
// We try to find a purse for this keyword, but even if we don't,
|
|
810
693
|
// we still make it a normal incoming payment.
|
|
811
694
|
const purseOrUndefined = purseKeywordRecord[keyword];
|
|
@@ -845,7 +728,7 @@ export function makeWalletRoot({
|
|
|
845
728
|
} else {
|
|
846
729
|
p = Promise.resolve();
|
|
847
730
|
}
|
|
848
|
-
return
|
|
731
|
+
return E.when(p, _ => petnameForBrand);
|
|
849
732
|
};
|
|
850
733
|
return addBrandPetname().then(async brandName => {
|
|
851
734
|
await updateAllIssuersState();
|
|
@@ -876,7 +759,7 @@ export function makeWalletRoot({
|
|
|
876
759
|
if (already) {
|
|
877
760
|
depositFacet = actions;
|
|
878
761
|
} else {
|
|
879
|
-
depositFacet = Far(
|
|
762
|
+
depositFacet = Far(WalletName.depositFacet, {
|
|
880
763
|
receive(paymentP) {
|
|
881
764
|
return E(actions).receive(paymentP);
|
|
882
765
|
},
|
|
@@ -886,13 +769,10 @@ export function makeWalletRoot({
|
|
|
886
769
|
const found = [...contactMapping.petnameToVal.entries()].find(
|
|
887
770
|
([_pn, { depositBoardId: dbid }]) => depositBoardId === dbid,
|
|
888
771
|
);
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
!found,
|
|
892
|
-
X`${q(found && found[0])} is already the petname for board ID ${q(
|
|
772
|
+
!found ||
|
|
773
|
+
Fail`${q(found && found[0])} is already the petname for board ID ${q(
|
|
893
774
|
depositBoardId,
|
|
894
|
-
)}
|
|
895
|
-
);
|
|
775
|
+
)}`;
|
|
896
776
|
|
|
897
777
|
const contact = harden(
|
|
898
778
|
addMeta({
|
|
@@ -1035,7 +915,7 @@ export function makeWalletRoot({
|
|
|
1035
915
|
const compile = amountKeywordRecord => {
|
|
1036
916
|
return Object.fromEntries(
|
|
1037
917
|
Object.entries(amountKeywordRecord).map(
|
|
1038
|
-
([keyword, { pursePetname, value
|
|
918
|
+
([keyword, { pursePetname, value }]) => {
|
|
1039
919
|
// Automatically convert numbers to Nats.
|
|
1040
920
|
if (typeof value === 'number') {
|
|
1041
921
|
value = Nat(value);
|
|
@@ -1044,7 +924,7 @@ export function makeWalletRoot({
|
|
|
1044
924
|
purseKeywordRecord[keyword] = purse;
|
|
1045
925
|
const brand = purseToBrand.get(purse);
|
|
1046
926
|
|
|
1047
|
-
return [keyword, { brand, value
|
|
927
|
+
return [keyword, { brand, value }];
|
|
1048
928
|
},
|
|
1049
929
|
),
|
|
1050
930
|
);
|
|
@@ -1093,8 +973,8 @@ export function makeWalletRoot({
|
|
|
1093
973
|
return compiled;
|
|
1094
974
|
};
|
|
1095
975
|
|
|
1096
|
-
/** @type {
|
|
1097
|
-
const dappOrigins =
|
|
976
|
+
/** @type {MapStore<string, DappRecord>} */
|
|
977
|
+
const dappOrigins = makeScalarMapStore('dappOrigin');
|
|
1098
978
|
const { notifier: dappsNotifier, updater: dappsUpdater } =
|
|
1099
979
|
/** @type {NotifierRecord<DappRecord[]>} */ (makeNotifierKit([]));
|
|
1100
980
|
|
|
@@ -1351,7 +1231,7 @@ export function makeWalletRoot({
|
|
|
1351
1231
|
.hasExited()
|
|
1352
1232
|
.then(exited => {
|
|
1353
1233
|
if (!exited) {
|
|
1354
|
-
|
|
1234
|
+
subscribeToUpdates(id, seat);
|
|
1355
1235
|
}
|
|
1356
1236
|
});
|
|
1357
1237
|
|
|
@@ -1388,8 +1268,8 @@ export function makeWalletRoot({
|
|
|
1388
1268
|
return ret;
|
|
1389
1269
|
}
|
|
1390
1270
|
|
|
1391
|
-
/** @type {
|
|
1392
|
-
const idToPaymentRecord =
|
|
1271
|
+
/** @type {MapStore<number, PaymentRecord>} */
|
|
1272
|
+
const idToPaymentRecord = makeScalarMapStore('paymentId');
|
|
1393
1273
|
const { updater: paymentsUpdater, notifier: paymentsNotifier } =
|
|
1394
1274
|
/** @type {NotifierRecord<PaymentRecord[]>} */ (makeNotifierKit([]));
|
|
1395
1275
|
/**
|
|
@@ -1430,7 +1310,7 @@ export function makeWalletRoot({
|
|
|
1430
1310
|
|
|
1431
1311
|
/**
|
|
1432
1312
|
* @param {ERef<Payment>} paymentP
|
|
1433
|
-
* @param {Purse | Petname
|
|
1313
|
+
* @param {Purse | Petname} [depositTo]
|
|
1434
1314
|
*/
|
|
1435
1315
|
const addPayment = async (paymentP, depositTo = undefined) => {
|
|
1436
1316
|
// We don't even create the record until we resolve the payment.
|
|
@@ -1482,7 +1362,7 @@ export function makeWalletRoot({
|
|
|
1482
1362
|
await updateAllPurseState();
|
|
1483
1363
|
}
|
|
1484
1364
|
|
|
1485
|
-
const pendingEnableAutoDeposits =
|
|
1365
|
+
const pendingEnableAutoDeposits = makeScalarMapStore('brand');
|
|
1486
1366
|
async function doEnableAutoDeposit(pursePetname, updateState) {
|
|
1487
1367
|
const purse = purseMapping.petnameToVal.get(pursePetname);
|
|
1488
1368
|
const brand = purseToBrand.get(purse);
|
|
@@ -1537,7 +1417,6 @@ export function makeWalletRoot({
|
|
|
1537
1417
|
return E(board)
|
|
1538
1418
|
.getValue(boardId)
|
|
1539
1419
|
.then(value => {
|
|
1540
|
-
// @ts-expect-error type is too specific
|
|
1541
1420
|
context.ensureBoardId(boardId, value);
|
|
1542
1421
|
return acceptFn(petname, value);
|
|
1543
1422
|
});
|
|
@@ -1650,10 +1529,8 @@ export function makeWalletRoot({
|
|
|
1650
1529
|
/** @type {IssuerManager} */
|
|
1651
1530
|
const issuerManager = Far('IssuerManager', {
|
|
1652
1531
|
rename: async (petname, issuer) => {
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
`issuer has not been previously added`,
|
|
1656
|
-
);
|
|
1532
|
+
brandTable.hasByIssuer(issuer) ||
|
|
1533
|
+
Fail`issuer has not been previously added`;
|
|
1657
1534
|
const brandRecord = brandTable.getByIssuer(issuer);
|
|
1658
1535
|
brandMapping.renamePetname(petname, brandRecord.brand);
|
|
1659
1536
|
await updateAllState();
|
|
@@ -1712,7 +1589,7 @@ export function makeWalletRoot({
|
|
|
1712
1589
|
passStyleOf(offerResult) === 'copyRecord',
|
|
1713
1590
|
`offerResult must be a record to have a uiNotifier`,
|
|
1714
1591
|
);
|
|
1715
|
-
|
|
1592
|
+
offerResult.uiNotifier || Fail`offerResult does not have a uiNotifier`;
|
|
1716
1593
|
return offerResult.uiNotifier;
|
|
1717
1594
|
}
|
|
1718
1595
|
|
|
@@ -1735,11 +1612,9 @@ export function makeWalletRoot({
|
|
|
1735
1612
|
|
|
1736
1613
|
const { publicSubscribers } = offerResult;
|
|
1737
1614
|
publicSubscribers ||
|
|
1738
|
-
|
|
1739
|
-
X`offerResult ${offerResult} does not have publicSubscribers`,
|
|
1740
|
-
);
|
|
1615
|
+
Fail`offerResult ${offerResult} does not have publicSubscribers`;
|
|
1741
1616
|
passStyleOf(publicSubscribers) === 'copyRecord' ||
|
|
1742
|
-
|
|
1617
|
+
Fail`publicSubscribers ${publicSubscribers} must be a record`;
|
|
1743
1618
|
|
|
1744
1619
|
return publicSubscribers;
|
|
1745
1620
|
}
|
|
@@ -1805,13 +1680,10 @@ export function makeWalletRoot({
|
|
|
1805
1680
|
const idOnly =
|
|
1806
1681
|
(kind, lookup) =>
|
|
1807
1682
|
(...path) => {
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
1,
|
|
1811
|
-
X`${assert.quote(
|
|
1683
|
+
path.length === 1 ||
|
|
1684
|
+
Fail`${assert.quote(
|
|
1812
1685
|
kind,
|
|
1813
|
-
)} lookup must be called with a single offer ID, not ${path}
|
|
1814
|
-
);
|
|
1686
|
+
)} lookup must be called with a single offer ID, not ${path}`;
|
|
1815
1687
|
return lookup(path[0]);
|
|
1816
1688
|
};
|
|
1817
1689
|
makeLookup('offer', idOnly('offer', idToOffer.get));
|
|
@@ -1825,10 +1697,12 @@ export function makeWalletRoot({
|
|
|
1825
1697
|
|
|
1826
1698
|
const firstPathToLookup = createRootLookups();
|
|
1827
1699
|
|
|
1828
|
-
/** @type {ReturnType<typeof makeMarshal>} */
|
|
1700
|
+
/** @type {ReturnType<typeof import('@endo/marshal').makeMarshal>} */
|
|
1829
1701
|
const marshaller = harden({
|
|
1830
|
-
|
|
1831
|
-
|
|
1702
|
+
fromCapData: context.fromCapData,
|
|
1703
|
+
toCapData: context.toCapData,
|
|
1704
|
+
unserialize: context.fromCapData,
|
|
1705
|
+
serialize: context.toCapData,
|
|
1832
1706
|
});
|
|
1833
1707
|
|
|
1834
1708
|
const handleAcceptOfferAction = async offer => {
|
|
@@ -1855,7 +1729,7 @@ export function makeWalletRoot({
|
|
|
1855
1729
|
case 'suggestIssuer':
|
|
1856
1730
|
return handleSuggestIssuerAction(data);
|
|
1857
1731
|
default:
|
|
1858
|
-
throw
|
|
1732
|
+
throw Error(`Unknown wallet action ${type}`);
|
|
1859
1733
|
}
|
|
1860
1734
|
};
|
|
1861
1735
|
|
|
@@ -1873,15 +1747,11 @@ export function makeWalletRoot({
|
|
|
1873
1747
|
return E(firstValue).lookup(...remaining);
|
|
1874
1748
|
},
|
|
1875
1749
|
getMarshaller: () => marshaller,
|
|
1876
|
-
resolveAttMaker: attMaker => attMakerPK.resolve(attMaker),
|
|
1877
|
-
getAttMaker: () => attMakerPK.promise,
|
|
1878
1750
|
getDappCacheCoordinator: dappOrigin =>
|
|
1879
1751
|
dappOrigins.get(dappOrigin).cacheCoordinator,
|
|
1880
1752
|
getCacheCoordinator: () => sharedCacheCoordinator,
|
|
1881
1753
|
saveOfferResult,
|
|
1882
1754
|
getOfferResult,
|
|
1883
|
-
getAccountState,
|
|
1884
|
-
makeAttestationAmount,
|
|
1885
1755
|
waitForDappApproval,
|
|
1886
1756
|
getDappsNotifier() {
|
|
1887
1757
|
return dappsNotifier;
|
|
@@ -1969,14 +1839,16 @@ export function makeWalletRoot({
|
|
|
1969
1839
|
return board;
|
|
1970
1840
|
},
|
|
1971
1841
|
getAgoricNames(...path) {
|
|
1972
|
-
|
|
1842
|
+
if (!agoricNames) {
|
|
1843
|
+
throw Fail`agoricNames was not supplied to the wallet maker`;
|
|
1844
|
+
}
|
|
1973
1845
|
return E(agoricNames).lookup(...path);
|
|
1974
1846
|
},
|
|
1975
1847
|
getNamesByAddress(...path) {
|
|
1976
1848
|
if (namesByAddress === undefined) {
|
|
1977
1849
|
// TypeScript confused about `||` control flow so use `if` instead
|
|
1978
1850
|
// https://github.com/microsoft/TypeScript/issues/50739
|
|
1979
|
-
|
|
1851
|
+
throw Fail`namesByAddress was not supplied to the wallet maker`;
|
|
1980
1852
|
}
|
|
1981
1853
|
return E(namesByAddress).lookup(...path);
|
|
1982
1854
|
},
|
|
@@ -2009,7 +1881,10 @@ export function makeWalletRoot({
|
|
|
2009
1881
|
.then(addInviteDepositFacet);
|
|
2010
1882
|
zoeInvitePurse = wallet.getPurse(ZOE_INVITE_PURSE_PETNAME);
|
|
2011
1883
|
|
|
2012
|
-
await E(myAddressNameAdmin).update(
|
|
1884
|
+
await E(myAddressNameAdmin).update(
|
|
1885
|
+
WalletName.depositFacet,
|
|
1886
|
+
selfDepositFacet,
|
|
1887
|
+
);
|
|
2013
1888
|
};
|
|
2014
1889
|
|
|
2015
1890
|
// Importing assets as virtual purses from the bank is a highly-trusted path.
|
|
@@ -2018,7 +1893,7 @@ export function makeWalletRoot({
|
|
|
2018
1893
|
// don't really trust.
|
|
2019
1894
|
// The param is{import('@agoric/vats/src/vat-bank.js').Bank} but that here triggers https://github.com/Agoric/agoric-sdk/issues/4620
|
|
2020
1895
|
const importBankAssets = async bank => {
|
|
2021
|
-
observeIteration(E(bank).getAssetSubscription(), {
|
|
1896
|
+
observeIteration(subscribeEach(E(bank).getAssetSubscription()), {
|
|
2022
1897
|
async updateState({ proposedName, issuerName, issuer, brand }) {
|
|
2023
1898
|
try {
|
|
2024
1899
|
issuerName = await addIssuer(issuerName, issuer);
|
package/src/types.js
CHANGED
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
* is safe to pass to the dapp UI.
|
|
86
86
|
* @property {() => Promise<ZoeService>} getZoe
|
|
87
87
|
* Get the Zoe Service
|
|
88
|
-
* @property {() => Promise<Board>} getBoard
|
|
88
|
+
* @property {() => Promise<import('@agoric/vats').Board>} getBoard
|
|
89
89
|
* Get the Board
|
|
90
90
|
* @property {(...path: Array<unknown>) => Promise<unknown>} getAgoricNames
|
|
91
91
|
* Get the curated Agoric public naming hub
|
|
@@ -117,7 +117,7 @@
|
|
|
117
117
|
* @property {Brand} brand
|
|
118
118
|
* @property {string} brandBoardId
|
|
119
119
|
* The board ID for this purse's brand
|
|
120
|
-
* @property {string
|
|
120
|
+
* @property {string} [depositBoardId]
|
|
121
121
|
* The board ID for the deposit-only facet of this purse
|
|
122
122
|
* @property {Petname} brandPetname
|
|
123
123
|
* The petname for this purse's brand
|
package/src/wallet.js
CHANGED
|
@@ -22,18 +22,18 @@ import './internal-types.js';
|
|
|
22
22
|
/**
|
|
23
23
|
* @typedef {{
|
|
24
24
|
* agoricNames: ERef<NameHub>,
|
|
25
|
-
* board: ERef<Board>,
|
|
25
|
+
* board: ERef<import('@agoric/vats').Board>,
|
|
26
26
|
* cacheStorageNode: ERef<StorageNode>,
|
|
27
27
|
* localTimerPollInterval?: bigint,
|
|
28
|
-
* localTimerService?: TimerService,
|
|
29
|
-
* myAddressNameAdmin: ERef<MyAddressNameAdmin>,
|
|
28
|
+
* localTimerService?: import('@agoric/time/src/types').TimerService,
|
|
29
|
+
* myAddressNameAdmin: ERef<import('@agoric/vats').MyAddressNameAdmin>,
|
|
30
30
|
* namesByAddress: ERef<NameHub>,
|
|
31
31
|
* timerDevice?: unknown,
|
|
32
32
|
* timerDeviceScale?: number,
|
|
33
33
|
* zoe: ERef<ZoeService>,
|
|
34
34
|
* }} StartupTerms
|
|
35
35
|
*
|
|
36
|
-
* @typedef {import('@agoric/vats
|
|
36
|
+
* @typedef {import('@agoric/vats').NameHub} NameHub
|
|
37
37
|
*/
|
|
38
38
|
|
|
39
39
|
export function buildRootObject(vatPowers) {
|
|
@@ -186,10 +186,6 @@ export function buildRootObject(vatPowers) {
|
|
|
186
186
|
await approve();
|
|
187
187
|
return walletAdmin.addOffer(offer, { ...meta, dappOrigin });
|
|
188
188
|
},
|
|
189
|
-
async getAccountState() {
|
|
190
|
-
await approve();
|
|
191
|
-
return walletAdmin.getAccountState();
|
|
192
|
-
},
|
|
193
189
|
async getOffersNotifier(status = null) {
|
|
194
190
|
await approve();
|
|
195
191
|
const { notifier, updater } = makeNotifierKit(inboxState);
|