Skip to content

Commit

Permalink
fix(pegasus): use bigints for nonces
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Feb 4, 2022
1 parent 208109f commit 9065d6e
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions packages/pegasus/src/pegasus.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,19 @@ const makePegasus = (zcf, board, namesByAddress) => {
* @property {LegacyMap<Denom, PromiseRecord<Courier>>} remoteDenomToCourierPK
* @property {IterationObserver<Denom>} remoteDenomPublication
* @property {Subscription<Denom>} remoteDenomSubscription
* @property {number} lastDenomNonce
* @property {bigint} lastDenomNonce Distinguish Pegasus-created denom names
* that are sent and received from a remote connection
* @property {(reason: CloseReason) => void} abort
*/

let lastLocalIssuerNonce = 0;
let lastLocalIssuerNonce = 0n;
/**
* Create a new issuer keyword (based on Local + nonce)
*
* @returns {string}
*/
const createLocalIssuerKeyword = () => {
lastLocalIssuerNonce += 1;
lastLocalIssuerNonce += 1n;
return `Local${lastLocalIssuerNonce}`;
};

Expand Down Expand Up @@ -172,11 +173,10 @@ const makePegasus = (zcf, board, namesByAddress) => {
async pegLocal(allegedName, localIssuer) {
checkAbort();

// We need the last nonce for our denom name.
localDenomState.lastDenomNonce += 1;
localDenomState.lastDenomNonce += 1n;
const remoteDenom = `pegasus${localDenomState.lastDenomNonce}`;

// Create a seat in which to keep our denomination.
// Create a seat in which to keep our escrowed ERTP assets of this denomination.
const { zcfSeat: poolSeat } = zcf.makeEmptySeatKit();

// Ensure the issuer can be used in Zoe offers.
Expand Down Expand Up @@ -298,7 +298,7 @@ const makePegasus = (zcf, board, namesByAddress) => {
localAddr,
remoteAddr,
remoteDenomToCourierPK,
lastDenomNonce: 0,
lastDenomNonce: 0n,
remoteDenomPublication,
remoteDenomSubscription,
abort: reason => {
Expand Down Expand Up @@ -336,10 +336,8 @@ const makePegasus = (zcf, board, namesByAddress) => {
const { remoteDenom } = parts;
assert.typeof(remoteDenom, 'string');

const {
remoteDenomToCourierPK,
remoteDenomPublication,
} = connectionToLocalDenomState.get(c);
const { remoteDenomToCourierPK, remoteDenomPublication } =
connectionToLocalDenomState.get(c);

if (!remoteDenomToCourierPK.has(remoteDenom)) {
// This is the first time we've heard of this denomination.
Expand Down

0 comments on commit 9065d6e

Please sign in to comment.