@tonconnect/protocol
Advanced tools
Comparing version 0.0.10 to 0.0.11
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SessionCrypto = void 0; | ||
var tslib_1 = require("tslib"); | ||
var utils_1 = require("../utils"); | ||
var tweetnacl_1 = tslib_1.__importDefault(require("tweetnacl")); | ||
const utils_1 = require("../utils"); | ||
const tweetnacl_1 = __importDefault(require("tweetnacl")); | ||
if (typeof require === 'function' && typeof global === 'object') { | ||
@@ -14,4 +16,4 @@ try { | ||
} | ||
var SessionCrypto = /** @class */ (function () { | ||
function SessionCrypto(keyPair) { | ||
class SessionCrypto { | ||
constructor(keyPair) { | ||
this.nonceLength = 24; | ||
@@ -21,6 +23,6 @@ this.keyPair = keyPair ? this.createKeypairFromString(keyPair) : this.createKeypair(); | ||
} | ||
SessionCrypto.prototype.createKeypair = function () { | ||
createKeypair() { | ||
return tweetnacl_1.default.box.keyPair(); | ||
}; | ||
SessionCrypto.prototype.createKeypairFromString = function (keyPair) { | ||
} | ||
createKeypairFromString(keyPair) { | ||
return { | ||
@@ -30,16 +32,16 @@ publicKey: (0, utils_1.hexToByteArray)(keyPair.publicKey), | ||
}; | ||
}; | ||
SessionCrypto.prototype.createNonce = function () { | ||
var buffer = new Uint8Array(this.nonceLength); | ||
} | ||
createNonce() { | ||
const buffer = new Uint8Array(this.nonceLength); | ||
return crypto.getRandomValues(buffer); | ||
}; | ||
SessionCrypto.prototype.encrypt = function (message, receiverPublicKey) { | ||
var encodedMessage = new TextEncoder().encode(message); | ||
var nonce = this.createNonce(); | ||
var encrypted = tweetnacl_1.default.box(encodedMessage, nonce, receiverPublicKey, this.keyPair.secretKey); | ||
} | ||
encrypt(message, receiverPublicKey) { | ||
const encodedMessage = new TextEncoder().encode(message); | ||
const nonce = this.createNonce(); | ||
const encrypted = tweetnacl_1.default.box(encodedMessage, nonce, receiverPublicKey, this.keyPair.secretKey); | ||
return (0, utils_1.concatUint8Arrays)(nonce, encrypted); | ||
}; | ||
SessionCrypto.prototype.decrypt = function (message, senderPublicKey) { | ||
var _a = (0, utils_1.splitToUint8Arrays)(message, this.nonceLength), nonce = _a[0], internalMessage = _a[1]; | ||
var decrypted = tweetnacl_1.default.box.open(internalMessage, nonce, senderPublicKey, this.keyPair.secretKey); | ||
} | ||
decrypt(message, senderPublicKey) { | ||
const [nonce, internalMessage] = (0, utils_1.splitToUint8Arrays)(message, this.nonceLength); | ||
const decrypted = tweetnacl_1.default.box.open(internalMessage, nonce, senderPublicKey, this.keyPair.secretKey); | ||
if (!decrypted) { | ||
@@ -49,4 +51,4 @@ throw new Error('Decryption error'); | ||
return new TextDecoder().decode(decrypted); | ||
}; | ||
SessionCrypto.prototype.stringifyKeypair = function () { | ||
} | ||
stringifyKeypair() { | ||
return { | ||
@@ -56,5 +58,4 @@ publicKey: (0, utils_1.toHexString)(this.keyPair.publicKey), | ||
}; | ||
}; | ||
return SessionCrypto; | ||
}()); | ||
} | ||
} | ||
exports.SessionCrypto = SessionCrypto; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./models"), exports); | ||
tslib_1.__exportStar(require("./crypto"), exports); | ||
tslib_1.__exportStar(require("./utils"), exports); | ||
__exportStar(require("./models"), exports); | ||
__exportStar(require("./crypto"), exports); | ||
__exportStar(require("./utils"), exports); |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./request"), exports); | ||
tslib_1.__exportStar(require("./connect-request"), exports); | ||
__exportStar(require("./request"), exports); | ||
__exportStar(require("./connect-request"), exports); |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CHAIN = void 0; | ||
var tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./app-message"), exports); | ||
tslib_1.__exportStar(require("./wallet-message"), exports); | ||
__exportStar(require("./app-message"), exports); | ||
__exportStar(require("./wallet-message"), exports); | ||
var CHAIN_1 = require("./CHAIN"); | ||
Object.defineProperty(exports, "CHAIN", { enumerable: true, get: function () { return CHAIN_1.CHAIN; } }); |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./wallet-event"), exports); | ||
tslib_1.__exportStar(require("./wallet-response"), exports); | ||
__exportStar(require("./wallet-event"), exports); | ||
__exportStar(require("./wallet-response"), exports); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Base64 = void 0; | ||
var buffer_1 = require("buffer"); | ||
const buffer_1 = require("buffer"); | ||
function encodeBuffer(buffer, urlSafe) { | ||
var encoded = buffer.toString('base64'); | ||
const encoded = buffer.toString('base64'); | ||
if (!urlSafe) { | ||
@@ -13,21 +13,19 @@ return encoded; | ||
function decodeToBuffer(message, urlSafe) { | ||
var value = urlSafe ? decodeURIComponent(message) : message; | ||
const value = urlSafe ? decodeURIComponent(message) : message; | ||
return buffer_1.Buffer.from(value, 'base64'); | ||
} | ||
function encode(value, urlSafe) { | ||
if (urlSafe === void 0) { urlSafe = false; } | ||
function encode(value, urlSafe = false) { | ||
if (!(value instanceof Uint8Array) && !(typeof value === 'string')) { | ||
value = JSON.stringify(value); | ||
} | ||
var buffer = buffer_1.Buffer.from(value); | ||
const buffer = buffer_1.Buffer.from(value); | ||
return encodeBuffer(buffer, urlSafe); | ||
} | ||
function decode(value, urlSafe) { | ||
if (urlSafe === void 0) { urlSafe = false; } | ||
var decodedBuffer = decodeToBuffer(value, urlSafe); | ||
function decode(value, urlSafe = false) { | ||
const decodedBuffer = decodeToBuffer(value, urlSafe); | ||
return { | ||
toString: function () { | ||
toString() { | ||
return decodedBuffer.toString('utf-8'); | ||
}, | ||
toObject: function () { | ||
toObject() { | ||
try { | ||
@@ -40,3 +38,3 @@ return JSON.parse(decodedBuffer.toString('utf-8')); | ||
}, | ||
toUint8Array: function () { | ||
toUint8Array() { | ||
return new Uint8Array(decodedBuffer.buffer, decodedBuffer.byteOffset, decodedBuffer.byteLength / Uint8Array.BYTES_PER_ELEMENT); | ||
@@ -47,4 +45,4 @@ } | ||
exports.Base64 = { | ||
encode: encode, | ||
decode: decode | ||
encode, | ||
decode | ||
}; |
@@ -5,3 +5,3 @@ "use strict"; | ||
function concatUint8Arrays(buffer1, buffer2) { | ||
var mergedArray = new Uint8Array(buffer1.length + buffer2.length); | ||
const mergedArray = new Uint8Array(buffer1.length + buffer2.length); | ||
mergedArray.set(buffer1); | ||
@@ -16,4 +16,4 @@ mergedArray.set(buffer2, buffer1.length); | ||
} | ||
var subArray1 = array.slice(0, index); | ||
var subArray2 = array.slice(index); | ||
const subArray1 = array.slice(0, index); | ||
const subArray2 = array.slice(index); | ||
return [subArray1, subArray2]; | ||
@@ -23,4 +23,4 @@ } | ||
function toHexString(byteArray) { | ||
var hexString = ''; | ||
byteArray.forEach(function (byte) { | ||
let hexString = ''; | ||
byteArray.forEach(byte => { | ||
hexString += ('0' + (byte & 0xff).toString(16)).slice(-2); | ||
@@ -33,6 +33,6 @@ }); | ||
if (hexString.length % 2 !== 0) { | ||
throw new Error("Cannot convert ".concat(hexString, " to bytesArray")); | ||
throw new Error(`Cannot convert ${hexString} to bytesArray`); | ||
} | ||
var result = new Uint8Array(hexString.length / 2); | ||
for (var i = 0; i < hexString.length; i += 2) { | ||
const result = new Uint8Array(hexString.length / 2); | ||
for (let i = 0; i < hexString.length; i += 2) { | ||
result[i / 2] = parseInt(hexString.slice(i, i + 2), 16); | ||
@@ -39,0 +39,0 @@ } |
{ | ||
"name": "@tonconnect/protocol", | ||
"version": "0.0.10", | ||
"version": "0.0.11", | ||
"repository": { | ||
@@ -5,0 +5,0 @@ "type": "git", |
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
34150
490