@tonconnect/protocol
Advanced tools
Comparing version 0.0.5 to 0.0.6
@@ -7,2 +7,9 @@ "use strict"; | ||
var tweetnacl_1 = tslib_1.__importDefault(require("tweetnacl")); | ||
if (typeof require === 'function' && typeof global === 'object') { | ||
try { | ||
// noinspection JSConstantReassignment | ||
global.crypto = require('crypto'); | ||
} | ||
catch (err) { } | ||
} | ||
var SessionCrypto = /** @class */ (function () { | ||
@@ -19,4 +26,4 @@ function SessionCrypto(keyPair) { | ||
return { | ||
publicKey: new TextEncoder().encode(keyPair.publicKey), | ||
secretKey: new TextEncoder().encode(keyPair.secretKey) | ||
publicKey: (0, utils_1.hexToByteArray)(keyPair.publicKey), | ||
secretKey: (0, utils_1.hexToByteArray)(keyPair.secretKey) | ||
}; | ||
@@ -44,4 +51,4 @@ }; | ||
return { | ||
publicKey: new TextDecoder().decode(this.keyPair.publicKey), | ||
secretKey: new TextDecoder().decode(this.keyPair.secretKey) | ||
publicKey: (0, utils_1.toHexString)(this.keyPair.publicKey), | ||
secretKey: (0, utils_1.toHexString)(this.keyPair.secretKey) | ||
}; | ||
@@ -48,0 +55,0 @@ }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Base64 = void 0; | ||
function toUrlSafe(str) { | ||
return encodeURIComponent(str); | ||
} | ||
function fromUrlSafe(str) { | ||
return decodeURIComponent(str); | ||
} | ||
function encodeString(str) { | ||
if (typeof btoa === 'function') { | ||
return btoa(str); | ||
var buffer_1 = require("buffer"); | ||
function encodeBuffer(buffer, urlSafe) { | ||
var encoded = buffer.toString('base64'); | ||
if (!urlSafe) { | ||
return encoded; | ||
} | ||
else if (typeof Buffer !== 'undefined' && | ||
Buffer !== null && | ||
typeof Buffer.from === 'function') { | ||
var buff = Buffer.from(str, 'base64'); | ||
return buff.toString('ascii'); | ||
} | ||
else { | ||
throw new Error('Base64 is not supported in your environment'); | ||
} | ||
return encodeURIComponent(encoded); | ||
} | ||
function decodeToString(encoded) { | ||
if (typeof atob === 'function') { | ||
return atob(fromUrlSafe(encoded)); | ||
} | ||
else if (typeof Buffer !== 'undefined' && | ||
Buffer !== null && | ||
typeof Buffer.from === 'function') { | ||
var buff = Buffer.from(fromUrlSafe(encoded)); | ||
return buff.toString('base64'); | ||
} | ||
else { | ||
throw new Error('Base64 is not supported in your environment'); | ||
} | ||
function decodeToBuffer(message, urlSafe) { | ||
var value = urlSafe ? decodeURIComponent(message) : message; | ||
return buffer_1.Buffer.from(value, 'base64'); | ||
} | ||
function encodeObject(obj) { | ||
return encodeString(JSON.stringify(obj)); | ||
} | ||
function encode(value, urlSafe) { | ||
if (urlSafe === void 0) { urlSafe = false; } | ||
if (value instanceof Uint8Array) { | ||
value = new TextDecoder().decode(value); | ||
if (urlSafe === void 0) { urlSafe = true; } | ||
if (!(value instanceof Uint8Array) && !(typeof value === 'string')) { | ||
value = JSON.stringify(value); | ||
} | ||
var encoded = typeof value === 'string' ? encodeString(value) : encodeObject(value); | ||
if (!urlSafe) { | ||
return encoded; | ||
} | ||
return toUrlSafe(encoded); | ||
var buffer = buffer_1.Buffer.from(value); | ||
return encodeBuffer(buffer, urlSafe); | ||
} | ||
function decode(value, urlSafe) { | ||
if (urlSafe === void 0) { urlSafe = false; } | ||
var decoded = urlSafe ? fromUrlSafe(decodeToString(value)) : decodeToString(value); | ||
if (urlSafe === void 0) { urlSafe = true; } | ||
var decodedBuffer = decodeToBuffer(value, urlSafe); | ||
return { | ||
toString: function () { | ||
return decoded; | ||
return decodedBuffer.toString('utf-8'); | ||
}, | ||
toObject: function () { | ||
try { | ||
return JSON.parse(decoded); | ||
return JSON.parse(decodedBuffer.toString('utf-8')); | ||
} | ||
@@ -68,3 +40,3 @@ catch (e) { | ||
toUint8Array: function () { | ||
return new TextEncoder().encode(decoded); | ||
return new Uint8Array(decodedBuffer.buffer, decodedBuffer.byteOffset, decodedBuffer.byteLength / Uint8Array.BYTES_PER_ELEMENT); | ||
} | ||
@@ -71,0 +43,0 @@ }; |
{ | ||
"name": "@tonconnect/protocol", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"repository": { | ||
@@ -23,3 +23,4 @@ "type": "git", | ||
"build": "npx rimraf lib && tsc", | ||
"build:production": "npx rimraf lib && tsc --sourceMap false" | ||
"build:production": "npx rimraf lib && tsc --sourceMap false", | ||
"test": "jest" | ||
}, | ||
@@ -31,4 +32,9 @@ "files": [ | ||
"types": "./lib/index.d.ts", | ||
"dependencies": { }, | ||
"dependencies": { | ||
"buffer": "^6.0.3" | ||
}, | ||
"devDependencies": { | ||
"jest": "^29.2.2", | ||
"ts-jest": "^29.0.3", | ||
"@types/jest": "^29.2.0" | ||
}, | ||
@@ -35,0 +41,0 @@ "nx": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31764
1
3
431
+ Addedbuffer@^6.0.3
+ Addedbase64-js@1.5.1(transitive)
+ Addedbuffer@6.0.3(transitive)
+ Addedieee754@1.2.1(transitive)