Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@agoric/captp

Package Overview
Dependencies
Maintainers
4
Versions
160
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@agoric/captp - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

86

lib/captp.js

@@ -11,2 +11,3 @@ // This logic was mostly lifted from @agoric/swingset-vat liveSlots.js

export function makeCapTP(ourId, send, bootstrapObj = undefined) {
let unplug = false;
const { serialize, unserialize } = makeMarshal(

@@ -24,4 +25,5 @@ // eslint-disable-next-line no-use-before-define

const valToSlot = new WeakMap();
const slotToVal = new Map(); // exports, answers
const slotToVal = new Map(); // exports
const questions = new Map(); // chosen by us
const answers = new Map(); // chosen by our peer
const imports = new Map(); // chosen by our peer

@@ -74,19 +76,29 @@

function makeRemote(slot) {
function makeQuestion() {
lastQuestionID += 1;
const questionID = lastQuestionID;
const pr = makeRemote(questionID);
questions.set(questionID, pr);
return [questionID, pr];
}
function makeRemote(target) {
const handler = {
GET(_o, prop) {
const [questionID, pr] = makeQuestion();
send({
type: 'CTP_CALL',
questionID,
target,
method: serialize(harden([prop])),
});
return harden(pr.p);
},
POST(_o, prop, args) {
// Support: o~.[prop](...args) remote method invocation
// FIXME: Implement a HandledPromise here to support pipelining.
const pr = {};
pr.p = new Promise((resolve, reject) => {
pr.res = resolve;
pr.rej = reject;
});
lastQuestionID += 1;
const questionID = lastQuestionID;
questions.set(questionID, pr);
const [questionID, pr] = makeQuestion();
send({
type: 'CTP_CALL',
questionID,
target: slot,
target,
method: serialize(harden([prop, args])),

@@ -136,2 +148,3 @@ });

// console.log('sending bootstrap', bootstrap);
answers.set(questionID, bootstrap);
send({

@@ -146,11 +159,19 @@ type: 'CTP_RETURN',

const [prop, args] = unserialize(obj.method);
const val = unserialize({
body: JSON.stringify({
[QCLASS]: 'slot',
index: 0,
}),
slots: [target],
});
HandledPromise.applyMethod(val, prop, args)
.then(res =>
let val;
if (answers.has(target)) {
val = answers.get(target);
} else {
val = unserialize({
body: JSON.stringify({
[QCLASS]: 'slot',
index: 0,
}),
slots: [target],
});
}
const hp = args
? HandledPromise.applyMethod(val, prop, args)
: HandledPromise.get(val, prop);
answers.set(questionID, hp);
hp.then(res =>
send({

@@ -190,2 +211,13 @@ type: 'CTP_RETURN',

},
CTP_ABORT(obj) {
const {exception} = obj;
unplug = true;
for (const pr of questions.values()) {
pr.rej(exception);
}
for (const pr of imports.values()) {
pr.rej(exception);
}
send(obj);
},
};

@@ -195,10 +227,3 @@

const getBootstrap = () => {
const pr = {};
pr.p = new Promise((resolve, reject) => {
pr.res = resolve;
pr.rej = reject;
});
lastQuestionID += 1;
const questionID = lastQuestionID;
questions.set(questionID, pr);
const [questionID, pr] = makeQuestion();
send({

@@ -214,2 +239,5 @@ type: 'CTP_BOOTSTRAP',

const dispatch = obj => {
if (unplug) {
return false;
}
const fn = handler[obj.type];

@@ -216,0 +244,0 @@ if (fn) {

{
"name": "@agoric/captp",
"version": "1.0.0",
"version": "1.0.1",
"description": "Capability Transfer Protocol for distributed objects",

@@ -49,3 +49,3 @@ "keywords": [

"dependencies": {
"@agoric/eventual-send": "^0.4.3",
"@agoric/eventual-send": "^0.4.4",
"@agoric/harden": "^0.0.4",

@@ -52,0 +52,0 @@ "@agoric/marshal": "^0.1.1",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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