New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@cardcore/util

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cardcore/util - npm Package Compare versions

Comparing version 0.0.1-73a2e966 to 0.0.1-79fba478

dist/keys.js

41

dist/box.js

@@ -13,9 +13,12 @@ "use strict";

var boxCache = {};
var Box = {
open: function open(boxId, box, me) {
open: function open(state, boxId) {
var box = state.game.boxes[boxId];
var privateKey = void 0;
if (box.privateKey) {
privateKey = box.privateKey;
} else if (box.keys[me.id]) {
privateKey = Box.getPrivate(box, me);
} else if (state.client && state.client.keys && box.keys[state.client.keys.id]) {
privateKey = Box.getPrivate(state, boxId);
}

@@ -31,10 +34,26 @@ if (!privateKey) {

},
getPrivate: function getPrivate(box, me) {
getPrivate: function getPrivate(state, boxId) {
var box = state.game.boxes[boxId];
var me = state.client.keys;
return _ssbKeys2.default.unbox(box.keys[me.id], me);
},
traverse: function traverse(boxId, boxes, me) {
if (!boxes[boxId]) {
traverse: function traverse(state, boxId) {
if (typeof state === "string") {
throw new Error("deprecated call to Box.traverse");
}
if (boxCache[boxId]) {
return boxCache[boxId];
}
var result = this._traverse(state, boxId);
if (result) {
boxCache[boxId] = result;
}
return result;
},
_traverse: function _traverse(state, boxId) {
if (!state.game.boxes[boxId]) {
return boxId; // idk maybe a unitId or something
}
var boxContents = Box.open(boxId, boxes[boxId], me);
var boxContents = Box.open(state, boxId);
if (!boxContents) {

@@ -44,5 +63,5 @@ // dang, couldn't open it. done!

}
if (boxes[boxContents]) {
if (state.game.boxes[boxContents]) {
// hey, this box had a box in it! keep going!
return Box.traverse(boxContents, boxes, me);
return Box._traverse(state, boxContents);
}

@@ -97,4 +116,4 @@ // got something that wasn't a box — we're done!

},
addKey: function addKey(box, me, ownerId) {
var boxMasterPrivateKey = _ssbKeys2.default.unbox(box.keys[me.id], me);
addKey: function addKey(state, boxId, ownerId) {
var boxMasterPrivateKey = this.getPrivate(state, boxId);
return _ssbKeys2.default.box(boxMasterPrivateKey, [{

@@ -101,0 +120,0 @@ id: ownerId,

@@ -6,2 +6,4 @@ "use strict";

});
var REMOTE_ACTION = exports.REMOTE_ACTION = "__REMOTE_ACTION";
var LOCATION_FIELD = exports.LOCATION_FIELD = "field";

@@ -8,0 +10,0 @@ var LOCATION_DECK = exports.LOCATION_DECK = "deck";

@@ -20,2 +20,5 @@ "use strict";

}
if (game.game) {
game = game.game;
}
return (0, _ssbKeys.hash)((0, _jsonStableStringify2.default)(game))

@@ -22,0 +25,0 @@ // switch up the two url-unsafe characters in base64

@@ -6,3 +6,3 @@ "use strict";

});
exports.hashState = exports.Box = undefined;
exports.Keys = exports.hashState = exports.Box = undefined;

@@ -74,17 +74,12 @@ var _targetHelper = require("./target-helper");

});
exports.serverFetch = serverFetch;
var _isomorphicFetch = require("isomorphic-fetch");
var _keys = require("./keys");
var _isomorphicFetch2 = _interopRequireDefault(_isomorphicFetch);
var Keys = _interopRequireWildcard(_keys);
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function serverFetch(url) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
return _isomorphicFetch2.default.apply(undefined, ["" + url].concat(args));
}
exports.Keys = Keys;
//# sourceMappingURL=index.js.map

@@ -16,2 +16,8 @@ "use strict";

var _box = require("./box");
var _box2 = _interopRequireDefault(_box);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var noop = function noop(x) {

@@ -25,3 +31,3 @@ return x;

* @export
* @param {object} state
* @param {object} game
* @param {object} target

@@ -37,8 +43,10 @@ * @property {string} target.player

var hasFullState = !!state.game;
var game = hasFullState ? state.game : state;
var units = {};
var owners = {};
if (target.unitId) {
units[target.unitId] = state.units[target.unitId];
owners[target.unitId] = Object.keys(state.players).find(function (playerId) {
return state.players[playerId].field.includes(target.unitId);
units[target.unitId] = game.units[target.unitId];
owners[target.unitId] = Object.keys(game.players).find(function (playerId) {
return game.players[playerId].field.includes(target.unitId);
});

@@ -48,8 +56,8 @@ } else {

if (!target.player) {
players = state.playerOrder;
players = game.playerOrder;
} else if (target.player === _constants.PLAYER_SELF) {
players = [state.turn];
players = [game.turn];
} else if (target.player === _constants.PLAYER_ENEMY) {
players = state.playerOrder.filter(function (p) {
return p !== state.turn;
players = game.playerOrder.filter(function (p) {
return p !== game.turn;
});

@@ -69,3 +77,3 @@ } else {

try {
for (var _iterator = Object.entries(state.players)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
for (var _iterator = Object.entries(game.players)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var _ref = _step.value;

@@ -82,3 +90,3 @@

if (types.includes(_constants.TYPE_FACE)) {
units[player.unitId] = state.units[player.unitId];
units[player.unitId] = game.units[player.unitId];
_owners[player.unitId] = playerId;

@@ -102,5 +110,17 @@ }

for (var _iterator3 = player[location][Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
var unitId = _step3.value;
var boxId = _step3.value;
units[unitId] = state.units[unitId];
if (!hasFullState) {
throw new Error("Deprecated call to target(), need full state");
}
var unitId = _box2.default.traverse(state, boxId);
if (!unitId) {
console.warn("Tried to target something I can't decrypt, " + JSON.stringify({
location: location,
boxId: boxId,
playerId: playerId
}));
continue;
}
units[unitId] = game.units[unitId];
_owners[unitId] = playerId;

@@ -192,4 +212,4 @@ }

function targetArray(state, action) {
return Object.values(target(state, action, function (unit, details) {
function targetArray(game, action) {
return Object.values(target(game, action, function (unit, details) {
return Object.assign({}, details, { unit: unit });

@@ -196,0 +216,0 @@ }));

{
"name": "@cardcore/util",
"version": "0.0.1-73a2e966",
"version": "0.0.1-79fba478",
"description": "various streamcards utilities",

@@ -18,3 +18,3 @@ "main": "dist/index.js",

},
"gitHead": "73a2e966a0bcb213e019931d58fb94c0472fdf84"
"gitHead": "79fba4784f0e15e530e674e512e3f7a116cd7849"
}
import ssbKeys from "@streamplace/ssb-keys";
const boxCache = {};
const Box = {
open(boxId, box, me) {
open(state, boxId) {
const box = state.game.boxes[boxId];
let privateKey;
if (box.privateKey) {
privateKey = box.privateKey;
} else if (box.keys[me.id]) {
privateKey = Box.getPrivate(box, me);
} else if (
state.client &&
state.client.keys &&
box.keys[state.client.keys.id]
) {
privateKey = Box.getPrivate(state, boxId);
}

@@ -21,11 +28,28 @@ if (!privateKey) {

getPrivate(box, me) {
getPrivate(state, boxId) {
const box = state.game.boxes[boxId];
const me = state.client.keys;
return ssbKeys.unbox(box.keys[me.id], me);
},
traverse(boxId, boxes, me) {
if (!boxes[boxId]) {
traverse(state, boxId) {
if (typeof state === "string") {
throw new Error("deprecated call to Box.traverse");
}
if (boxCache[boxId]) {
return boxCache[boxId];
}
const result = this._traverse(state, boxId);
if (result) {
boxCache[boxId] = result;
}
return result;
},
_traverse(state, boxId) {
if (!state.game.boxes[boxId]) {
return boxId; // idk maybe a unitId or something
}
const boxContents = Box.open(boxId, boxes[boxId], me);
const boxContents = Box.open(state, boxId);
if (!boxContents) {

@@ -35,5 +59,5 @@ // dang, couldn't open it. done!

}
if (boxes[boxContents]) {
if (state.game.boxes[boxContents]) {
// hey, this box had a box in it! keep going!
return Box.traverse(boxContents, boxes, me);
return Box._traverse(state, boxContents);
}

@@ -63,4 +87,4 @@ // got something that wasn't a box — we're done!

addKey(box, me, ownerId) {
const boxMasterPrivateKey = ssbKeys.unbox(box.keys[me.id], me);
addKey(state, boxId, ownerId) {
const boxMasterPrivateKey = this.getPrivate(state, boxId);
return ssbKeys.box(boxMasterPrivateKey, [

@@ -67,0 +91,0 @@ {

@@ -0,1 +1,3 @@

export const REMOTE_ACTION = "__REMOTE_ACTION";
export const LOCATION_FIELD = "field";

@@ -2,0 +4,0 @@ export const LOCATION_DECK = "deck";

@@ -8,2 +8,5 @@ import { hash } from "@streamplace/ssb-keys";

}
if (game.game) {
game = game.game;
}
return (

@@ -10,0 +13,0 @@ hash(stringify(game))

@@ -7,6 +7,3 @@ export * from "./target-helper";

export { default as hashState } from "./hash-state";
import fetch from "isomorphic-fetch";
export function serverFetch(url, ...args) {
return fetch(`${url}`, ...args);
}
import * as Keys from "./keys";
export { Keys };

@@ -10,2 +10,3 @@ import {

import { rando } from "./random-util";
import Box from "./box";

@@ -18,3 +19,3 @@ const noop = x => x;

* @export
* @param {object} state
* @param {object} game
* @param {object} target

@@ -28,8 +29,10 @@ * @property {string} target.player

export function target(state, target, func = noop) {
const hasFullState = !!state.game;
let game = hasFullState ? state.game : state;
let units = {};
const owners = {};
if (target.unitId) {
units[target.unitId] = state.units[target.unitId];
owners[target.unitId] = Object.keys(state.players).find(playerId => {
return state.players[playerId].field.includes(target.unitId);
units[target.unitId] = game.units[target.unitId];
owners[target.unitId] = Object.keys(game.players).find(playerId => {
return game.players[playerId].field.includes(target.unitId);
});

@@ -39,7 +42,7 @@ } else {

if (!target.player) {
players = state.playerOrder;
players = game.playerOrder;
} else if (target.player === PLAYER_SELF) {
players = [state.turn];
players = [game.turn];
} else if (target.player === PLAYER_ENEMY) {
players = state.playerOrder.filter(p => p !== state.turn);
players = game.playerOrder.filter(p => p !== game.turn);
} else {

@@ -53,3 +56,3 @@ players = [target.player];

for (const [playerId, player] of Object.entries(state.players)) {
for (const [playerId, player] of Object.entries(game.players)) {
if (!players.includes(playerId)) {

@@ -59,3 +62,3 @@ continue;

if (types.includes(TYPE_FACE)) {
units[player.unitId] = state.units[player.unitId];
units[player.unitId] = game.units[player.unitId];
owners[player.unitId] = playerId;

@@ -67,4 +70,18 @@ }

for (const location of locations) {
for (const unitId of player[location]) {
units[unitId] = state.units[unitId];
for (const boxId of player[location]) {
if (!hasFullState) {
throw new Error("Deprecated call to target(), need full state");
}
const unitId = Box.traverse(state, boxId);
if (!unitId) {
console.warn(
`Tried to target something I can't decrypt, ${JSON.stringify({
location,
boxId,
playerId
})}`
);
continue;
}
units[unitId] = game.units[unitId];
owners[unitId] = playerId;

@@ -93,5 +110,5 @@ }

export function targetArray(state, action) {
export function targetArray(game, action) {
return Object.values(
target(state, action, (unit, details) => {
target(game, action, (unit, details) => {
return { ...details, unit };

@@ -98,0 +115,0 @@ })

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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