Comparing version 11.15.0 to 11.16.0
/// <reference types="node" /> | ||
import { Cell } from "../boc/Cell"; | ||
export declare function safeSign(cell: Cell, secretKey: Buffer): Buffer; | ||
export declare function safeSignVerify(cell: Cell, signature: Buffer, publicKey: Buffer): boolean; | ||
export declare function safeSign(cell: Cell, secretKey: Buffer, seed?: string): Buffer; | ||
export declare function safeSignVerify(cell: Cell, signature: Buffer, publicKey: Buffer, seed?: string): boolean; |
@@ -5,12 +5,21 @@ "use strict"; | ||
const ton_crypto_1 = require("ton-crypto"); | ||
function createSafeSignHash(cell) { | ||
return (0, ton_crypto_1.sha256_sync)(Buffer.concat([Buffer.from([0xff, 0xff]), Buffer.from('ton-safe-sign-magic'), cell.hash()])); | ||
const MIN_SEED_LENGTH = 8; | ||
const MAX_SEED_LENGTH = 64; | ||
function createSafeSignHash(cell, seed) { | ||
let seedData = Buffer.from(seed); | ||
if (seedData.length > MAX_SEED_LENGTH) { | ||
throw Error('Seed can\t be longer than 64 bytes'); | ||
} | ||
if (seedData.length < MIN_SEED_LENGTH) { | ||
throw Error('Seed must be at least 8 bytes'); | ||
} | ||
return (0, ton_crypto_1.sha256_sync)(Buffer.concat([Buffer.from([0xff, 0xff]), seedData, cell.hash()])); | ||
} | ||
function safeSign(cell, secretKey) { | ||
return (0, ton_crypto_1.sign)(createSafeSignHash(cell), secretKey); | ||
function safeSign(cell, secretKey, seed = 'ton-safe-sign-magic') { | ||
return (0, ton_crypto_1.sign)(createSafeSignHash(cell, seed), secretKey); | ||
} | ||
exports.safeSign = safeSign; | ||
function safeSignVerify(cell, signature, publicKey) { | ||
return (0, ton_crypto_1.signVerify)(createSafeSignHash(cell), signature, publicKey); | ||
function safeSignVerify(cell, signature, publicKey, seed = 'ton-safe-sign-magic') { | ||
return (0, ton_crypto_1.signVerify)(createSafeSignHash(cell, seed), signature, publicKey); | ||
} | ||
exports.safeSignVerify = safeSignVerify; |
{ | ||
"name": "ton", | ||
"version": "11.15.0", | ||
"version": "11.16.0", | ||
"repository": "https://github.com/tonwhales/ton.git", | ||
@@ -5,0 +5,0 @@ "author": "Steve Korshakov <steve@korshakov.com>", |
433160
11193