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

@playnation/game-sdk

Package Overview
Dependencies
Maintainers
0
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@playnation/game-sdk - npm Package Compare versions

Comparing version 1.0.5 to 1.0.6-beta.0

dist/index.cjs

598

dist/index.js

@@ -1,14 +0,588 @@

import { ErrorCode as e } from "./types.js";
import { IframeSDK as f } from "./websdk.js";
import { signPayload as t } from "./utils/signature.js";
import { u8aToHex as a } from "./utils/u8aToHex.js";
import { deepCopy as n } from "./utils/utils.js";
import { PlaynationSDKError as i } from "./utils/error.js";
var G = Object.defineProperty;
var m = Object.getOwnPropertySymbols;
var M = Object.prototype.hasOwnProperty, B = Object.prototype.propertyIsEnumerable;
var P = (t, e, r) => e in t ? G(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
var U = (t, e) => {
var r = {};
for (var n in t)
M.call(t, n) && e.indexOf(n) < 0 && (r[n] = t[n]);
if (t != null && m)
for (var n of m(t))
e.indexOf(n) < 0 && B.call(t, n) && (r[n] = t[n]);
return r;
};
var w = (t, e, r) => P(t, typeof e != "symbol" ? e + "" : e, r);
var c = (t, e, r) => new Promise((n, s) => {
var i = (h) => {
try {
o(r.next(h));
} catch (a) {
s(a);
}
}, f = (h) => {
try {
o(r.throw(h));
} catch (a) {
s(a);
}
}, o = (h) => h.done ? n(h.value) : Promise.resolve(h.value).then(i, f);
o((r = r.apply(t, e)).next());
});
var D = /* @__PURE__ */ ((t) => (t[t.SYSTEM_ERROR = -1] = "SYSTEM_ERROR", t[t.INVALID_REQUEST = 10] = "INVALID_REQUEST", t[t.INVALID_SCORE = 120] = "INVALID_SCORE", t[t.USER_REJECT = 130] = "USER_REJECT", t[t.NOT_ENOUGH_ENERGY = 150] = "NOT_ENOUGH_ENERGY", t[t.TOUR_NOT_AVAILABLE = 100] = "TOUR_NOT_AVAILABLE", t[t.NOT_ENOUGH_NPS = 110] = "NOT_ENOUGH_NPS", t[t.NOT_ENOUGH_TICKET = 140] = "NOT_ENOUGH_TICKET", t))(D || {});
const b = class b {
constructor() {
w(this, "requestId", 0);
// Create request and listen for the response
w(this, "requests", {});
}
init(e) {
return c(this, null, function* () {
return yield this.dispatch("INIT", e);
});
}
getPlayer() {
return c(this, null, function* () {
return yield this.dispatch("GET_PLAYER");
});
}
getTournament() {
return c(this, null, function* () {
const e = yield this.dispatch("GET_TOURNAMENT");
if (e.id)
return e;
});
}
buyTickets() {
return c(this, null, function* () {
return yield this.dispatch("BUY_TICKET");
});
}
play() {
return c(this, null, function* () {
return yield this.dispatch("PLAY");
});
}
trackScore(e) {
return c(this, null, function* () {
return yield this.dispatch("TRACK_SCORE", e);
});
}
signResult(e) {
return c(this, null, function* () {
return yield this.dispatch("SIGN_RESULT", e);
});
}
updateState(e) {
return c(this, null, function* () {
return yield this.dispatch("UPDATE_STATE", e);
});
}
showLeaderboard() {
return c(this, null, function* () {
return yield this.dispatch("SHOW_LEADERBOARD");
});
}
showShop() {
return c(this, null, function* () {
return yield this.dispatch("SHOW_SHOP");
});
}
getLeaderboard(e) {
return c(this, null, function* () {
return yield this.dispatch("GET_LEADERBOARD", e);
});
}
getInGameItems() {
return c(this, null, function* () {
return yield this.dispatch("GET_INGAME_ITEMS");
});
}
buyInGameItem(e) {
return c(this, null, function* () {
return yield this.dispatch("BUY_INGAME_ITEM", e);
});
}
exit(e = !0) {
return c(this, null, function* () {
return yield this.dispatch("EXIT", e);
});
}
exitToListGames(e = !0) {
return c(this, null, function* () {
return yield this.dispatch("EXIT_TO_LIST_GAMES", e);
});
}
getVersion() {
return "v1";
}
triggerHapticFeedback(e) {
return c(this, null, function* () {
yield this.dispatch("TRIGGER_HAPTIC_FEEDBACK", e);
});
}
useInGameItem(e) {
return c(this, null, function* () {
return yield this.dispatch("USE_INGAME_ITEM", e);
});
}
dispatch(e, r, n = 60) {
return c(this, null, function* () {
return new Promise((s, i) => {
const f = this.requestId + 1;
this.requestId = f, n && setTimeout(() => {
i("timeout"), delete this.requests[f];
}, n * 1e3), this.requests[f] = { resolve: s, reject: i };
const o = { source: "game-sdk", requestId: f, action: e, data: r };
window.parent.postMessage(o, "*");
});
});
}
onMessage(e) {
if (typeof e.data != "object") return;
const f = e.data, { requestId: r } = f, n = U(f, ["requestId"]);
if (!this.requests[r]) return;
const { resolve: s, reject: i } = this.requests[r];
if (n.error) {
const o = new Error(n.error);
o.code = n.code, i(o);
} else
s((n == null ? void 0 : n._payload) || n);
delete this.requests[r];
}
static get instance() {
return b._instance || (b._instance = new b(), window.addEventListener("message", b._instance.onMessage.bind(b._instance))), b._instance;
}
};
// Singleton
w(b, "_instance");
let S = b;
window.PlaynationGameSDK || (window.PlaynationGameSDK = S.instance);
const k = (t) => new TextEncoder().encode(t);
var K = typeof Buffer != "undefined" && Buffer.from ? function(t) {
return Buffer.from(t, "utf8");
} : k;
function l(t) {
return t instanceof Uint8Array ? t : typeof t == "string" ? K(t) : ArrayBuffer.isView(t) ? new Uint8Array(t.buffer, t.byteOffset, t.byteLength / Uint8Array.BYTES_PER_ELEMENT) : new Uint8Array(t);
}
function T(t) {
return typeof t == "string" ? t.length === 0 : t.byteLength === 0;
}
var L = { name: "SHA-256" }, I = {
name: "HMAC",
hash: L
}, q = new Uint8Array([
227,
176,
196,
66,
152,
252,
28,
20,
154,
251,
244,
200,
153,
111,
185,
36,
39,
174,
65,
228,
100,
155,
147,
76,
164,
149,
153,
27,
120,
82,
184,
85
]);
const Y = {};
function g() {
return typeof window != "undefined" ? window : typeof self != "undefined" ? self : Y;
}
var V = (
/** @class */
function() {
function t(e) {
this.toHash = new Uint8Array(0), this.secret = e, this.reset();
}
return t.prototype.update = function(e) {
if (!T(e)) {
var r = l(e), n = new Uint8Array(this.toHash.byteLength + r.byteLength);
n.set(this.toHash, 0), n.set(r, this.toHash.byteLength), this.toHash = n;
}
}, t.prototype.digest = function() {
var e = this;
return this.key ? this.key.then(function(r) {
return g().crypto.subtle.sign(I, r, e.toHash).then(function(n) {
return new Uint8Array(n);
});
}) : T(this.toHash) ? Promise.resolve(q) : Promise.resolve().then(function() {
return g().crypto.subtle.digest(L, e.toHash);
}).then(function(r) {
return Promise.resolve(new Uint8Array(r));
});
}, t.prototype.reset = function() {
var e = this;
this.toHash = new Uint8Array(0), this.secret && this.secret !== void 0 && (this.key = new Promise(function(r, n) {
g().crypto.subtle.importKey("raw", l(e.secret), I, !1, ["sign"]).then(r, n);
}), this.key.catch(function() {
}));
}, t;
}()
);
function j(t, e, r, n) {
function s(i) {
return i instanceof r ? i : new r(function(f) {
f(i);
});
}
return new (r || (r = Promise))(function(i, f) {
function o(u) {
try {
a(n.next(u));
} catch (x) {
f(x);
}
}
function h(u) {
try {
a(n.throw(u));
} catch (x) {
f(x);
}
}
function a(u) {
u.done ? i(u.value) : s(u.value).then(o, h);
}
a((n = n.apply(t, e || [])).next());
});
}
function J(t, e) {
var r = { label: 0, sent: function() {
if (i[0] & 1) throw i[1];
return i[1];
}, trys: [], ops: [] }, n, s, i, f;
return f = { next: o(0), throw: o(1), return: o(2) }, typeof Symbol == "function" && (f[Symbol.iterator] = function() {
return this;
}), f;
function o(a) {
return function(u) {
return h([a, u]);
};
}
function h(a) {
if (n) throw new TypeError("Generator is already executing.");
for (; f && (f = 0, a[0] && (r = 0)), r; ) try {
if (n = 1, s && (i = a[0] & 2 ? s.return : a[0] ? s.throw || ((i = s.return) && i.call(s), 0) : s.next) && !(i = i.call(s, a[1])).done) return i;
switch (s = 0, i && (a = [a[0] & 2, i.value]), a[0]) {
case 0:
case 1:
i = a;
break;
case 4:
return r.label++, { value: a[1], done: !1 };
case 5:
r.label++, s = a[1], a = [0];
continue;
case 7:
a = r.ops.pop(), r.trys.pop();
continue;
default:
if (i = r.trys, !(i = i.length > 0 && i[i.length - 1]) && (a[0] === 6 || a[0] === 2)) {
r = 0;
continue;
}
if (a[0] === 3 && (!i || a[1] > i[0] && a[1] < i[3])) {
r.label = a[1];
break;
}
if (a[0] === 6 && r.label < i[1]) {
r.label = i[1], i = a;
break;
}
if (i && r.label < i[2]) {
r.label = i[2], r.ops.push(a);
break;
}
i[2] && r.ops.pop(), r.trys.pop();
continue;
}
a = e.call(t, r);
} catch (u) {
a = [6, u], s = 0;
} finally {
n = i = 0;
}
if (a[0] & 5) throw a[1];
return { value: a[0] ? a[1] : void 0, done: !0 };
}
}
var p = 64, W = 32, $ = new Uint32Array([
1116352408,
1899447441,
3049323471,
3921009573,
961987163,
1508970993,
2453635748,
2870763221,
3624381080,
310598401,
607225278,
1426881987,
1925078388,
2162078206,
2614888103,
3248222580,
3835390401,
4022224774,
264347078,
604807628,
770255983,
1249150122,
1555081692,
1996064986,
2554220882,
2821834349,
2952996808,
3210313671,
3336571891,
3584528711,
113926993,
338241895,
666307205,
773529912,
1294757372,
1396182291,
1695183700,
1986661051,
2177026350,
2456956037,
2730485921,
2820302411,
3259730800,
3345764771,
3516065817,
3600352804,
4094571909,
275423344,
430227734,
506948616,
659060556,
883997877,
958139571,
1322822218,
1537002063,
1747873779,
1955562222,
2024104815,
2227730452,
2361852424,
2428436474,
2756734187,
3204031479,
3329325298
]), C = [
1779033703,
3144134277,
1013904242,
2773480762,
1359893119,
2600822924,
528734635,
1541459225
], F = Math.pow(2, 53) - 1, E = (
/** @class */
function() {
function t() {
this.state = Int32Array.from(C), this.temp = new Int32Array(64), this.buffer = new Uint8Array(64), this.bufferLength = 0, this.bytesHashed = 0, this.finished = !1;
}
return t.prototype.update = function(e) {
if (this.finished)
throw new Error("Attempted to update an already finished hash.");
var r = 0, n = e.byteLength;
if (this.bytesHashed += n, this.bytesHashed * 8 > F)
throw new Error("Cannot hash more than 2^53 - 1 bits");
for (; n > 0; )
this.buffer[this.bufferLength++] = e[r++], n--, this.bufferLength === p && (this.hashBuffer(), this.bufferLength = 0);
}, t.prototype.digest = function() {
if (!this.finished) {
var e = this.bytesHashed * 8, r = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength), n = this.bufferLength;
if (r.setUint8(this.bufferLength++, 128), n % p >= p - 8) {
for (var s = this.bufferLength; s < p; s++)
r.setUint8(s, 0);
this.hashBuffer(), this.bufferLength = 0;
}
for (var s = this.bufferLength; s < p - 8; s++)
r.setUint8(s, 0);
r.setUint32(p - 8, Math.floor(e / 4294967296), !0), r.setUint32(p - 4, e), this.hashBuffer(), this.finished = !0;
}
for (var i = new Uint8Array(W), s = 0; s < 8; s++)
i[s * 4] = this.state[s] >>> 24 & 255, i[s * 4 + 1] = this.state[s] >>> 16 & 255, i[s * 4 + 2] = this.state[s] >>> 8 & 255, i[s * 4 + 3] = this.state[s] >>> 0 & 255;
return i;
}, t.prototype.hashBuffer = function() {
for (var e = this, r = e.buffer, n = e.state, s = n[0], i = n[1], f = n[2], o = n[3], h = n[4], a = n[5], u = n[6], x = n[7], y = 0; y < p; y++) {
if (y < 16)
this.temp[y] = (r[y * 4] & 255) << 24 | (r[y * 4 + 1] & 255) << 16 | (r[y * 4 + 2] & 255) << 8 | r[y * 4 + 3] & 255;
else {
var d = this.temp[y - 2], O = (d >>> 17 | d << 15) ^ (d >>> 19 | d << 13) ^ d >>> 10;
d = this.temp[y - 15];
var R = (d >>> 7 | d << 25) ^ (d >>> 18 | d << 14) ^ d >>> 3;
this.temp[y] = (O + this.temp[y - 7] | 0) + (R + this.temp[y - 16] | 0);
}
var v = (((h >>> 6 | h << 26) ^ (h >>> 11 | h << 21) ^ (h >>> 25 | h << 7)) + (h & a ^ ~h & u) | 0) + (x + ($[y] + this.temp[y] | 0) | 0) | 0, H = ((s >>> 2 | s << 30) ^ (s >>> 13 | s << 19) ^ (s >>> 22 | s << 10)) + (s & i ^ s & f ^ i & f) | 0;
x = u, u = a, a = h, h = o + v | 0, o = f, f = i, i = s, s = v + H | 0;
}
n[0] += s, n[1] += i, n[2] += f, n[3] += o, n[4] += h, n[5] += a, n[6] += u, n[7] += x;
}, t;
}()
), X = (
/** @class */
function() {
function t(e) {
this.secret = e, this.hash = new E(), this.reset();
}
return t.prototype.update = function(e) {
if (!(T(e) || this.error))
try {
this.hash.update(l(e));
} catch (r) {
this.error = r;
}
}, t.prototype.digestSync = function() {
if (this.error)
throw this.error;
return this.outer ? (this.outer.finished || this.outer.update(this.hash.digest()), this.outer.digest()) : this.hash.digest();
}, t.prototype.digest = function() {
return j(this, void 0, void 0, function() {
return J(this, function(e) {
return [2, this.digestSync()];
});
});
}, t.prototype.reset = function() {
if (this.hash = new E(), this.secret) {
this.outer = new E();
var e = Q(this.secret), r = new Uint8Array(p);
r.set(e);
for (var n = 0; n < p; n++)
e[n] ^= 54, r[n] ^= 92;
this.hash.update(e), this.outer.update(r);
for (var n = 0; n < e.byteLength; n++)
e[n] = 0;
}
}, t;
}()
);
function Q(t) {
var e = l(t);
if (e.byteLength > p) {
var r = new E();
r.update(e), e = r.digest();
}
var n = new Uint8Array(p);
return n.set(e), n;
}
var Z = [
"decrypt",
"digest",
"encrypt",
"exportKey",
"generateKey",
"importKey",
"sign",
"verify"
];
function z(t) {
if (tt(t) && typeof t.crypto.subtle == "object") {
var e = t.crypto.subtle;
return et(e);
}
return !1;
}
function tt(t) {
if (typeof t == "object" && typeof t.crypto == "object") {
var e = t.crypto.getRandomValues;
return typeof e == "function";
}
return !1;
}
function et(t) {
return t && Z.every(function(e) {
return typeof t[e] == "function";
});
}
var rt = (
/** @class */
function() {
function t(e) {
z(g()) ? this.hash = new V(e) : this.hash = new X(e);
}
return t.prototype.update = function(e, r) {
this.hash.update(l(e));
}, t.prototype.digest = function() {
return this.hash.digest();
}, t.prototype.reset = function() {
this.hash.reset();
}, t;
}()
);
const _ = new Array(256), N = new Array(256 * 256);
for (let t = 0; t < 256; t++)
_[t] = t.toString(16).padStart(2, "0");
for (let t = 0; t < 256; t++) {
const e = t << 8;
for (let r = 0; r < 256; r++)
N[e | r] = _[t] + _[r];
}
function A(t, e) {
const r = t.length % 2 | 0, n = t.length - r | 0;
for (let s = 0; s < n; s += 2)
e += N[t[s] << 8 | t[s + 1]];
return r && (e += _[t[n] | 0]), e;
}
function nt(t, e = -1, r = !0) {
const n = r ? "0x" : "";
if (t != null && t.length) {
if (e > 0) {
const s = Math.ceil(e / 8);
if (t.length > s)
return `${A(t.subarray(0, s / 2), n)}…${A(t.subarray(t.length - s / 2), "")}`;
}
} else return n;
return A(t, n);
}
function it(t, e) {
return c(this, null, function* () {
const r = new rt(e);
r.update(JSON.stringify(t));
const n = yield r.digest();
return nt(n);
});
}
function at(t) {
return JSON.parse(JSON.stringify(t));
}
class ft extends Error {
constructor(r, n) {
super(r);
w(this, "code");
this.name = "PlaynationSDKError", this.code = n;
}
}
export {
e as ErrorCode,
f as IframeSDK,
i as PlaynationSDKError,
n as deepCopy,
t as signPayload,
a as u8aToHex
D as ErrorCode,
S as IframeSDK,
ft as PlaynationSDKError,
at as deepCopy,
it as signPayload,
nt as u8aToHex
};

2

package.json
{
"name": "@playnation/game-sdk",
"version": "1.0.5",
"version": "1.0.6-beta.0",
"description": "SDK for the games on Playnation",

@@ -5,0 +5,0 @@ "repository": {

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