Huge News!Announcing our $40M Series B led by Abstract Ventures.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-1f746c46 to 0.0.1-2a70ec43

dist/box.js

20

dist/index.js

@@ -54,2 +54,22 @@ "use strict";

});
var _box = require("./box");
Object.defineProperty(exports, "Box", {
enumerable: true,
get: function get() {
return _interopRequireDefault(_box).default;
}
});
var _hashState = require("./hash-state");
Object.defineProperty(exports, "hashState", {
enumerable: true,
get: function get() {
return _interopRequireDefault(_hashState).default;
}
});
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
//# sourceMappingURL=index.js.map

15

dist/random-util.js

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

var _ssbKeys = require("ssb-keys");
var _ssbKeys = require("@streamplace/ssb-keys");

@@ -38,6 +38,5 @@ var _ssbKeys2 = _interopRequireDefault(_ssbKeys);

if (!seed) {
seed = _ssbKeys2.default.hash("" + Math.random());
if (seed) {
this.setSeed(seed);
}
this.setSeed(seed);
}

@@ -68,2 +67,5 @@

value: function next() {
if (!this.seed) {
throw new Error("tried to use RNG without providing a seed!");
}
return this.seed = this.seed * 16807 % 2147483647;

@@ -76,2 +78,7 @@ }

}
}, {
key: "clearSeed",
value: function clearSeed() {
this.seed = null;
}
}]);

@@ -78,0 +85,0 @@

@@ -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.error("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 @@ }));

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

});
exports.uid = exports.traverseSecret = exports.getRightPlayer = exports.getLeftPlayer = exports.rotateArray = undefined;
exports.range = range;
var _randomUtil = require("./random-util");
var _ssbKeys = require("@streamplace/ssb-keys");
var _ssbKeys2 = _interopRequireDefault(_ssbKeys);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }

@@ -41,2 +50,24 @@

/**
* Get the player to the left of this one
*/
var getLeftPlayer = exports.getLeftPlayer = function getLeftPlayer(playerId, players) {
var index = players.indexOf(playerId);
if (index === 0) {
return players[players.length - 1];
}
return players[index - 1];
};
/**
* Get the player to the right of this one
*/
var getRightPlayer = exports.getRightPlayer = function getRightPlayer(playerId, players) {
var index = players.indexOf(playerId);
if (index === players.length - 1) {
return players[0];
}
return players[index + 1];
};
var traverseSecret = exports.traverseSecret = function traverseSecret(secret, secrets) {

@@ -52,12 +83,5 @@ if (!secret || !secret.secret) {

/**
* id-generation function that assumes that all users will execute it in the _exact_ same order.
* this is.... hopefully reasonable.
*/
var cur = 0;
var uid = exports.uid = function uid() {
var res = "id-" + cur;
cur += 1;
return res;
return "id-" + _randomUtil.rando.next();
};
//# sourceMappingURL=util.js.map
{
"name": "@cardcore/util",
"version": "0.0.1-1f746c46",
"version": "0.0.1-2a70ec43",
"description": "various streamcards utilities",

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

},
"gitHead": "1f746c46c9911e36a1e9be89edf6da902e8ff20f"
"dependencies": {
"@streamplace/ssb-keys": "7.0.21",
"isomorphic-fetch": "^2.2.1",
"json-stable-stringify": "^1.0.1"
},
"gitHead": "2a70ec4389c35623465d67f06b8f39eac294ced5"
}

@@ -5,1 +5,3 @@ export * from "./target-helper";

export * from "./constants";
export { default as Box } from "./box";
export { default as hashState } from "./hash-state";
// very simple PRNG from here https://gist.github.com/blixt/f17b47c62508be59987b
import ssbKeys from "ssb-keys";
import ssbKeys from "@streamplace/ssb-keys";

@@ -14,6 +14,5 @@ export function shuffle(arr, func = Math.random) {

constructor(seed) {
if (!seed) {
seed = ssbKeys.hash(`${Math.random()}`);
if (seed) {
this.setSeed(seed);
}
this.setSeed(seed);
}

@@ -40,2 +39,5 @@

next() {
if (!this.seed) {
throw new Error("tried to use RNG without providing a seed!");
}
return (this.seed = (this.seed * 16807) % 2147483647);

@@ -47,4 +49,8 @@ }

}
clearSeed() {
this.seed = null;
}
}
export const rando = new RandomUtil();

@@ -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.error(
`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 @@ })

@@ -0,1 +1,4 @@

import { rando } from "./random-util";
import ssbKeys from "@streamplace/ssb-keys";
/**

@@ -27,2 +30,24 @@ * Like Python's range. Get an array of numbers from 0 to n.

/**
* Get the player to the left of this one
*/
export const getLeftPlayer = (playerId, players) => {
const index = players.indexOf(playerId);
if (index === 0) {
return players[players.length - 1];
}
return players[index - 1];
};
/**
* Get the player to the right of this one
*/
export const getRightPlayer = (playerId, players) => {
const index = players.indexOf(playerId);
if (index === players.length - 1) {
return players[0];
}
return players[index + 1];
};
export const traverseSecret = (secret, secrets) => {

@@ -38,11 +63,4 @@ if (!secret || !secret.secret) {

/**
* id-generation function that assumes that all users will execute it in the _exact_ same order.
* this is.... hopefully reasonable.
*/
let cur = 0;
export const uid = () => {
let res = `id-${cur}`;
cur += 1;
return res;
return `id-${rando.next()}`;
};

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