@tonconnect/protocol
Advanced tools
Comparing version 0.0.19 to 0.0.20
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Base64 = void 0; | ||
const buffer_1 = require("buffer"); | ||
function encodeBuffer(buffer, urlSafe) { | ||
const encoded = buffer.toString('base64'); | ||
const tweetnacl_util_1 = __importDefault(require("tweetnacl-util")); | ||
function encodeUint8Array(value, urlSafe) { | ||
const encoded = tweetnacl_util_1.default.encodeBase64(value); | ||
if (!urlSafe) { | ||
@@ -12,22 +15,30 @@ return encoded; | ||
} | ||
function decodeToBuffer(message, urlSafe) { | ||
const value = urlSafe ? decodeURIComponent(message) : message; | ||
return buffer_1.Buffer.from(value, 'base64'); | ||
function decodeToUint8Array(value, urlSafe) { | ||
if (urlSafe) { | ||
value = decodeURIComponent(value); | ||
} | ||
return tweetnacl_util_1.default.decodeBase64(value); | ||
} | ||
function encode(value, urlSafe = false) { | ||
if (!(value instanceof Uint8Array) && !(typeof value === 'string')) { | ||
value = JSON.stringify(value); | ||
let uint8Array; | ||
if (value instanceof Uint8Array) { | ||
uint8Array = value; | ||
} | ||
const buffer = buffer_1.Buffer.from(value); | ||
return encodeBuffer(buffer, urlSafe); | ||
else { | ||
if (typeof value !== 'string') { | ||
value = JSON.stringify(value); | ||
} | ||
uint8Array = tweetnacl_util_1.default.decodeUTF8(value); | ||
} | ||
return encodeUint8Array(uint8Array, urlSafe); | ||
} | ||
function decode(value, urlSafe = false) { | ||
const decodedBuffer = decodeToBuffer(value, urlSafe); | ||
const decodedUint8Array = decodeToUint8Array(value, urlSafe); | ||
return { | ||
toString() { | ||
return decodedBuffer.toString('utf-8'); | ||
return tweetnacl_util_1.default.encodeUTF8(decodedUint8Array); | ||
}, | ||
toObject() { | ||
try { | ||
return JSON.parse(decodedBuffer.toString('utf-8')); | ||
return JSON.parse(tweetnacl_util_1.default.encodeUTF8(decodedUint8Array)); | ||
} | ||
@@ -39,3 +50,3 @@ catch (e) { | ||
toUint8Array() { | ||
return new Uint8Array(decodedBuffer.buffer, decodedBuffer.byteOffset, decodedBuffer.byteLength / Uint8Array.BYTES_PER_ELEMENT); | ||
return decodedUint8Array; | ||
} | ||
@@ -42,0 +53,0 @@ }; |
{ | ||
"name": "@tonconnect/protocol", | ||
"version": "0.0.19", | ||
"version": "0.0.20", | ||
"repository": { | ||
@@ -32,3 +32,3 @@ "type": "git", | ||
"dependencies": { | ||
"buffer": "^6.0.3" | ||
"tweetnacl-util": "^0.15.1" | ||
}, | ||
@@ -35,0 +35,0 @@ "devDependencies": { |
@@ -5,4 +5,6 @@ # TON Connect protocol models | ||
ℹ️ If you want to integrate TonConnect to your dApp, you should use [@tonconnect/sdk](https://www.npmjs.com/package/@tonconnect/sdk) | ||
ℹ️ If you want to integrate TonConnect to your dApp, you should use [@tonconnect/sdk](https://www.npmjs.com/package/@tonconnect/sdk) | ||
[Latest API documentation](https://ton-connect.github.io/sdk/modules/_tonconnect_protocol.html) | ||
## Summary | ||
@@ -9,0 +11,0 @@ Package contains protocol requests, responses and event models and encoding, decoding functions. |
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
36489
540
47
+ Addedtweetnacl-util@^0.15.1
+ Addedtweetnacl-util@0.15.1(transitive)
- Removedbuffer@^6.0.3
- Removedbase64-js@1.5.1(transitive)
- Removedbuffer@6.0.3(transitive)
- Removedieee754@1.2.1(transitive)