@playnation/game-sdk
Advanced tools
Comparing version 1.0.7-beta.3 to 1.0.7
@@ -1,3 +0,1 @@ | ||
export * from './types'; | ||
export * from './websdk'; | ||
export * from './utils'; | ||
export {}; |
@@ -1,19 +0,19 @@ | ||
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 = Object.defineProperty; | ||
var T = Object.getOwnPropertySymbols; | ||
var P = Object.prototype.hasOwnProperty, k = Object.prototype.propertyIsEnumerable; | ||
var O = (e, t, r) => t in e ? R(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r; | ||
var L = (e, t) => { | ||
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]); | ||
for (var n in e) | ||
P.call(e, n) && t.indexOf(n) < 0 && (r[n] = e[n]); | ||
if (e != null && T) | ||
for (var n of T(e)) | ||
t.indexOf(n) < 0 && k.call(e, n) && (r[n] = e[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 l = (e, t, r) => O(e, typeof t != "symbol" ? t + "" : t, r); | ||
var o = (e, t, r) => new Promise((n, s) => { | ||
var i = (h) => { | ||
try { | ||
o(r.next(h)); | ||
c(r.next(h)); | ||
} catch (a) { | ||
@@ -24,151 +24,22 @@ s(a); | ||
try { | ||
o(r.throw(h)); | ||
c(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()); | ||
}, c = (h) => h.done ? n(h.value) : Promise.resolve(h.value).then(i, f); | ||
c((r = r.apply(e, t)).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); | ||
const C = (e) => new TextEncoder().encode(e); | ||
var N = typeof Buffer != "undefined" && Buffer.from ? function(e) { | ||
return Buffer.from(e, "utf8"); | ||
} : C; | ||
function w(e) { | ||
return e instanceof Uint8Array ? e : typeof e == "string" ? N(e) : ArrayBuffer.isView(e) ? new Uint8Array(e.buffer, e.byteOffset, e.byteLength / Uint8Array.BYTES_PER_ELEMENT) : new Uint8Array(e); | ||
} | ||
function T(t) { | ||
return typeof t == "string" ? t.length === 0 : t.byteLength === 0; | ||
function m(e) { | ||
return typeof e == "string" ? e.length === 0 : e.byteLength === 0; | ||
} | ||
var L = { name: "SHA-256" }, I = { | ||
var I = { name: "SHA-256" }, U = { | ||
name: "HMAC", | ||
hash: L | ||
hash: I | ||
}, q = new Uint8Array([ | ||
@@ -208,38 +79,38 @@ 227, | ||
]); | ||
const Y = {}; | ||
const D = {}; | ||
function g() { | ||
return typeof window != "undefined" ? window : typeof self != "undefined" ? self : Y; | ||
return typeof window != "undefined" ? window : typeof self != "undefined" ? self : D; | ||
} | ||
var V = ( | ||
var K = ( | ||
/** @class */ | ||
function() { | ||
function t(e) { | ||
this.toHash = new Uint8Array(0), this.secret = e, this.reset(); | ||
function e(t) { | ||
this.toHash = new Uint8Array(0), this.secret = t, this.reset(); | ||
} | ||
return t.prototype.update = function(e) { | ||
if (!T(e)) { | ||
var r = l(e), n = new Uint8Array(this.toHash.byteLength + r.byteLength); | ||
return e.prototype.update = function(t) { | ||
if (!m(t)) { | ||
var r = w(t), 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; | ||
}, e.prototype.digest = function() { | ||
var t = this; | ||
return this.key ? this.key.then(function(r) { | ||
return g().crypto.subtle.sign(I, r, e.toHash).then(function(n) { | ||
return g().crypto.subtle.sign(U, r, t.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); | ||
}) : m(this.toHash) ? Promise.resolve(q) : Promise.resolve().then(function() { | ||
return g().crypto.subtle.digest(I, t.toHash); | ||
}).then(function(r) { | ||
return Promise.resolve(new Uint8Array(r)); | ||
}); | ||
}, t.prototype.reset = function() { | ||
var e = this; | ||
}, e.prototype.reset = function() { | ||
var t = 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); | ||
g().crypto.subtle.importKey("raw", w(t.secret), U, !1, ["sign"]).then(r, n); | ||
}), this.key.catch(function() { | ||
})); | ||
}, t; | ||
}, e; | ||
}() | ||
); | ||
function j(t, e, r, n) { | ||
function Y(e, t, r, n) { | ||
function s(i) { | ||
@@ -251,3 +122,3 @@ return i instanceof r ? i : new r(function(f) { | ||
return new (r || (r = Promise))(function(i, f) { | ||
function o(u) { | ||
function c(u) { | ||
try { | ||
@@ -267,8 +138,8 @@ a(n.next(u)); | ||
function a(u) { | ||
u.done ? i(u.value) : s(u.value).then(o, h); | ||
u.done ? i(u.value) : s(u.value).then(c, h); | ||
} | ||
a((n = n.apply(t, e || [])).next()); | ||
a((n = n.apply(e, t || [])).next()); | ||
}); | ||
} | ||
function J(t, e) { | ||
function j(e, t) { | ||
var r = { label: 0, sent: function() { | ||
@@ -278,6 +149,6 @@ if (i[0] & 1) throw 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 f = { next: c(0), throw: c(1), return: c(2) }, typeof Symbol == "function" && (f[Symbol.iterator] = function() { | ||
return this; | ||
}), f; | ||
function o(a) { | ||
function c(a) { | ||
return function(u) { | ||
@@ -324,3 +195,3 @@ return h([a, u]); | ||
} | ||
a = e.call(t, r); | ||
a = t.call(e, r); | ||
} catch (u) { | ||
@@ -335,3 +206,3 @@ a = [6, u], s = 0; | ||
} | ||
var p = 64, W = 32, $ = new Uint32Array([ | ||
var d = 64, W = 32, $ = new Uint32Array([ | ||
1116352408, | ||
@@ -401,3 +272,3 @@ 1899447441, | ||
3329325298 | ||
]), C = [ | ||
]), F = [ | ||
1779033703, | ||
@@ -411,27 +282,27 @@ 3144134277, | ||
1541459225 | ||
], F = Math.pow(2, 53) - 1, E = ( | ||
], X = Math.pow(2, 53) - 1, A = ( | ||
/** @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; | ||
function e() { | ||
this.state = Int32Array.from(F), 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) { | ||
return e.prototype.update = function(t) { | ||
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) | ||
var r = 0, n = t.byteLength; | ||
if (this.bytesHashed += n, this.bytesHashed * 8 > X) | ||
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() { | ||
this.buffer[this.bufferLength++] = t[r++], n--, this.bufferLength === d && (this.hashBuffer(), this.bufferLength = 0); | ||
}, e.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++) | ||
var t = 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 % d >= d - 8) { | ||
for (var s = this.bufferLength; s < d; s++) | ||
r.setUint8(s, 0); | ||
this.hashBuffer(), this.bufferLength = 0; | ||
} | ||
for (var s = this.bufferLength; s < p - 8; s++) | ||
for (var s = this.bufferLength; s < d - 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; | ||
r.setUint32(d - 8, Math.floor(t / 4294967296), !0), r.setUint32(d - 4, t), this.hashBuffer(), this.finished = !0; | ||
} | ||
@@ -441,65 +312,65 @@ for (var i = new Uint8Array(W), s = 0; s < 8; s++) | ||
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++) { | ||
}, e.prototype.hashBuffer = function() { | ||
for (var t = this, r = t.buffer, n = t.state, s = n[0], i = n[1], f = n[2], c = n[3], h = n[4], a = n[5], u = n[6], x = n[7], y = 0; y < d; 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 p = this.temp[y - 2], G = (p >>> 17 | p << 15) ^ (p >>> 19 | p << 13) ^ p >>> 10; | ||
p = this.temp[y - 15]; | ||
var M = (p >>> 7 | p << 25) ^ (p >>> 18 | p << 14) ^ p >>> 3; | ||
this.temp[y] = (G + this.temp[y - 7] | 0) + (M + 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; | ||
var _ = (((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, B = ((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 = c + _ | 0, c = f, f = i, i = s, s = _ + B | 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; | ||
n[0] += s, n[1] += i, n[2] += f, n[3] += c, n[4] += h, n[5] += a, n[6] += u, n[7] += x; | ||
}, e; | ||
}() | ||
), X = ( | ||
), J = ( | ||
/** @class */ | ||
function() { | ||
function t(e) { | ||
this.secret = e, this.hash = new E(), this.reset(); | ||
function e(t) { | ||
this.secret = t, this.hash = new A(), this.reset(); | ||
} | ||
return t.prototype.update = function(e) { | ||
if (!(T(e) || this.error)) | ||
return e.prototype.update = function(t) { | ||
if (!(m(t) || this.error)) | ||
try { | ||
this.hash.update(l(e)); | ||
this.hash.update(w(t)); | ||
} catch (r) { | ||
this.error = r; | ||
} | ||
}, t.prototype.digestSync = function() { | ||
}, e.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) { | ||
}, e.prototype.digest = function() { | ||
return Y(this, void 0, void 0, function() { | ||
return j(this, function(t) { | ||
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; | ||
}, e.prototype.reset = function() { | ||
if (this.hash = new A(), this.secret) { | ||
this.outer = new A(); | ||
var t = Z(this.secret), r = new Uint8Array(d); | ||
r.set(t); | ||
for (var n = 0; n < d; n++) | ||
t[n] ^= 54, r[n] ^= 92; | ||
this.hash.update(t), this.outer.update(r); | ||
for (var n = 0; n < t.byteLength; n++) | ||
t[n] = 0; | ||
} | ||
}, t; | ||
}, e; | ||
}() | ||
); | ||
function Q(t) { | ||
var e = l(t); | ||
if (e.byteLength > p) { | ||
var r = new E(); | ||
r.update(e), e = r.digest(); | ||
function Z(e) { | ||
var t = w(e); | ||
if (t.byteLength > d) { | ||
var r = new A(); | ||
r.update(t), t = r.digest(); | ||
} | ||
var n = new Uint8Array(p); | ||
return n.set(e), n; | ||
var n = new Uint8Array(d); | ||
return n.set(t), n; | ||
} | ||
var Z = [ | ||
var z = [ | ||
"decrypt", | ||
@@ -514,86 +385,201 @@ "digest", | ||
]; | ||
function z(t) { | ||
if (tt(t) && typeof t.crypto.subtle == "object") { | ||
var e = t.crypto.subtle; | ||
return et(e); | ||
function Q(e) { | ||
if (V(e) && typeof e.crypto.subtle == "object") { | ||
var t = e.crypto.subtle; | ||
return tt(t); | ||
} | ||
return !1; | ||
} | ||
function tt(t) { | ||
if (typeof t == "object" && typeof t.crypto == "object") { | ||
var e = t.crypto.getRandomValues; | ||
return typeof e == "function"; | ||
function V(e) { | ||
if (typeof e == "object" && typeof e.crypto == "object") { | ||
var t = e.crypto.getRandomValues; | ||
return typeof t == "function"; | ||
} | ||
return !1; | ||
} | ||
function et(t) { | ||
return t && Z.every(function(e) { | ||
return typeof t[e] == "function"; | ||
function tt(e) { | ||
return e && z.every(function(t) { | ||
return typeof e[t] == "function"; | ||
}); | ||
} | ||
var rt = ( | ||
var et = ( | ||
/** @class */ | ||
function() { | ||
function t(e) { | ||
z(g()) ? this.hash = new V(e) : this.hash = new X(e); | ||
function e(t) { | ||
Q(g()) ? this.hash = new K(t) : this.hash = new J(t); | ||
} | ||
return t.prototype.update = function(e, r) { | ||
this.hash.update(l(e)); | ||
}, t.prototype.digest = function() { | ||
return e.prototype.update = function(t, r) { | ||
this.hash.update(w(t)); | ||
}, e.prototype.digest = function() { | ||
return this.hash.digest(); | ||
}, t.prototype.reset = function() { | ||
}, e.prototype.reset = function() { | ||
this.hash.reset(); | ||
}, t; | ||
}, e; | ||
}() | ||
); | ||
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; | ||
const E = new Array(256), H = new Array(256 * 256); | ||
for (let e = 0; e < 256; e++) | ||
E[e] = e.toString(16).padStart(2, "0"); | ||
for (let e = 0; e < 256; e++) { | ||
const t = e << 8; | ||
for (let r = 0; r < 256; r++) | ||
N[e | r] = _[t] + _[r]; | ||
H[t | r] = E[e] + E[r]; | ||
} | ||
function A(t, e) { | ||
const r = t.length % 2 | 0, n = t.length - r | 0; | ||
function v(e, t) { | ||
const r = e.length % 2 | 0, n = e.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; | ||
t += H[e[s] << 8 | e[s + 1]]; | ||
return r && (t += E[e[n] | 0]), t; | ||
} | ||
function nt(t, e = -1, r = !0) { | ||
function rt(e, t = -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), "")}`; | ||
if (e != null && e.length) { | ||
if (t > 0) { | ||
const s = Math.ceil(t / 8); | ||
if (e.length > s) | ||
return `${v(e.subarray(0, s / 2), n)}…${v(e.subarray(e.length - s / 2), "")}`; | ||
} | ||
} else return n; | ||
return A(t, n); | ||
return v(e, n); | ||
} | ||
function it(t, e) { | ||
return c(this, null, function* () { | ||
const r = new rt(e); | ||
r.update(JSON.stringify(t)); | ||
function nt(e, t) { | ||
return o(this, null, function* () { | ||
const r = new et(t); | ||
r.update(JSON.stringify(e)); | ||
const n = yield r.digest(); | ||
return nt(n); | ||
return rt(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; | ||
const b = class b { | ||
constructor() { | ||
l(this, "requestId", 0); | ||
// Create request and listen for the response | ||
l(this, "requests", {}); | ||
} | ||
} | ||
export { | ||
D as ErrorCode, | ||
S as IframeSDK, | ||
ft as PlaynationSDKError, | ||
at as deepCopy, | ||
it as signPayload, | ||
nt as u8aToHex | ||
init(t) { | ||
return o(this, null, function* () { | ||
return yield this.dispatch("INIT", t); | ||
}); | ||
} | ||
getPlayer() { | ||
return o(this, null, function* () { | ||
return yield this.dispatch("GET_PLAYER"); | ||
}); | ||
} | ||
getTournament() { | ||
return o(this, null, function* () { | ||
const t = yield this.dispatch("GET_TOURNAMENT"); | ||
if (t.id) | ||
return t; | ||
}); | ||
} | ||
buyTickets() { | ||
return o(this, null, function* () { | ||
return yield this.dispatch("BUY_TICKET"); | ||
}); | ||
} | ||
play() { | ||
return o(this, null, function* () { | ||
return yield this.dispatch("PLAY"); | ||
}); | ||
} | ||
trackScore(t) { | ||
return o(this, null, function* () { | ||
return yield this.dispatch("TRACK_SCORE", t); | ||
}); | ||
} | ||
signResult(t) { | ||
return o(this, null, function* () { | ||
return yield this.dispatch("SIGN_RESULT", t); | ||
}); | ||
} | ||
updateState(t) { | ||
return o(this, null, function* () { | ||
return yield this.dispatch("UPDATE_STATE", t); | ||
}); | ||
} | ||
showLeaderboard() { | ||
return o(this, null, function* () { | ||
return yield this.dispatch("SHOW_LEADERBOARD"); | ||
}); | ||
} | ||
showShop() { | ||
return o(this, null, function* () { | ||
return yield this.dispatch("SHOW_SHOP"); | ||
}); | ||
} | ||
getLeaderboard(t) { | ||
return o(this, null, function* () { | ||
return yield this.dispatch("GET_LEADERBOARD", t); | ||
}); | ||
} | ||
getInGameItems() { | ||
return o(this, null, function* () { | ||
return yield this.dispatch("GET_INGAME_ITEMS"); | ||
}); | ||
} | ||
buyInGameItem(t) { | ||
return o(this, null, function* () { | ||
return yield this.dispatch("BUY_INGAME_ITEM", t); | ||
}); | ||
} | ||
exit(t = !0) { | ||
return o(this, null, function* () { | ||
return yield this.dispatch("EXIT", t); | ||
}); | ||
} | ||
exitToListGames(t = !0) { | ||
return o(this, null, function* () { | ||
return yield this.dispatch("EXIT_TO_LIST_GAMES", t); | ||
}); | ||
} | ||
getVersion() { | ||
return "v1"; | ||
} | ||
triggerHapticFeedback(t) { | ||
return o(this, null, function* () { | ||
yield this.dispatch("TRIGGER_HAPTIC_FEEDBACK", t); | ||
}); | ||
} | ||
useInGameItem(t) { | ||
return o(this, null, function* () { | ||
return yield this.dispatch("USE_INGAME_ITEM", t); | ||
}); | ||
} | ||
signPayload(t, r) { | ||
return o(this, null, function* () { | ||
return yield nt(t, r); | ||
}); | ||
} | ||
dispatch(t, r, n = 60) { | ||
return o(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 c = { source: "game-sdk", requestId: f, action: t, data: r }; | ||
window.parent.postMessage(c, "*"); | ||
}); | ||
}); | ||
} | ||
onMessage(t) { | ||
if (typeof t.data != "object") return; | ||
const f = t.data, { requestId: r } = f, n = L(f, ["requestId"]); | ||
if (!this.requests[r]) return; | ||
const { resolve: s, reject: i } = this.requests[r]; | ||
if (n.error) { | ||
const c = new Error(n.error); | ||
c.code = n.code, i(c); | ||
} 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 | ||
l(b, "_instance"); | ||
let S = b; | ||
window.PlaynationGameSDK = S.instance; |
@@ -30,2 +30,3 @@ import { BuyInGameItemResponse, BuyItemPayload, GameSDK, GetLeaderboardRequest, GetLeaderboardResponse, HapticFeedbackType, InGameItem, Player, PlayResponse, SDKInitParams, SignPayload, Tournament, TrackScorePayload, UpdateStatePayload, UseInGameItemResponse, UseItemPayload } from './types'; | ||
useInGameItem(payload: UseItemPayload): Promise<UseInGameItemResponse>; | ||
signPayload(payload: SignPayload, key: string): Promise<`0x${string}`>; | ||
private requests; | ||
@@ -32,0 +33,0 @@ dispatch<T>(action: string, data?: any, timeout?: number): Promise<T>; |
{ | ||
"name": "@playnation/game-sdk", | ||
"version": "1.0.7-beta.3", | ||
"version": "1.0.7", | ||
"description": "SDK for the games on Playnation", | ||
@@ -5,0 +5,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
35278
852