Socket
Socket
Sign inDemoInstall

@terra-money/terra.js

Package Overview
Dependencies
55
Maintainers
5
Versions
230
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.4.18-beta.1 to 0.4.18-beta.2

46

dist/extension/index.d.ts
import { Msg } from '../core/Msg';
import { LCDClientConfig } from '../client';
declare type SendDataType = 'connect' | 'post';
declare type SendDataType = 'connect' | 'post' | 'sign';
interface SendData {

@@ -13,7 +13,51 @@ id: number | string;

constructor();
private generateId;
send(data: SendData): void;
on(name: string, callback: (payload: any) => void): void;
/**
* Request to Station Extension for connecting a wallet
*
* @returns {string} name 'onConnect'
* @returns {AccAddress} payload Terra account address
*/
connect(): number;
/**
* Request to Station Extension for signing tx
*
* @param msgs transaction messages to be signed
* @param account_number account number (optional)
* @param sequence sequence (optional)
*
* @return {string} name 'onSign'
* @return {object} payload
* @return {number} payload.id identifier
* @return {string} payload.origin origin address
* @return {Msg[]} payload.msgs requested msgs
* @return {boolean} payload.success
* @return {string} payload.result.public_key Hex encoded public key
* @return {string} payload.result.signature Base64 encoded signature
* @return {number} payload.result.recid Recovery id
*/
sign(msgs: Msg[], account_number?: number, sequence?: number): number;
/**
* Request to Station Extension for sign and post to LCD server
*
* @param msgs transaction messages to be signed
* @param lcdClientConfig LCDClientConfig (optional)
*
* @return {string} name 'onPost'
* @return {object} payload
* @return {number} payload.id identifier
* @return {string} payload.origin origin address
* @return {Msg[]} payload.msgs requested msgs
* @return {LCDClientConfig} payload.lcdClientConfig
* requested lcdClientConfig
* @return {boolean} payload.success
* @return {number|undefined} payload.result.code
* error code. undefined with successful tx
* @return {string} payload.result.raw_log raw log
* @return {string} payload.result.txhash transaction hash
*/
post(msgs: Msg[], lcdClientConfig?: LCDClientConfig): number;
}
export {};

@@ -17,2 +17,5 @@ "use strict";

}
Extension.prototype.generateId = function () {
return Date.now();
};
// low level function for sending message to extension.

@@ -28,4 +31,10 @@ // Do not use this function unless you know what you are doing.

};
/**
* Request to Station Extension for connecting a wallet
*
* @returns {string} name 'onConnect'
* @returns {AccAddress} payload Terra account address
*/
Extension.prototype.connect = function () {
var id = Date.now();
var id = this.generateId();
this.send({

@@ -37,4 +46,51 @@ id: id,

};
/**
* Request to Station Extension for signing tx
*
* @param msgs transaction messages to be signed
* @param account_number account number (optional)
* @param sequence sequence (optional)
*
* @return {string} name 'onSign'
* @return {object} payload
* @return {number} payload.id identifier
* @return {string} payload.origin origin address
* @return {Msg[]} payload.msgs requested msgs
* @return {boolean} payload.success
* @return {string} payload.result.public_key Hex encoded public key
* @return {string} payload.result.signature Base64 encoded signature
* @return {number} payload.result.recid Recovery id
*/
Extension.prototype.sign = function (msgs, account_number, sequence) {
var id = this.generateId();
this.send({
id: id,
type: 'sign',
msgs: msgs.map(function (msg) { return msg.toJSON(); }),
account_number: account_number,
sequence: sequence,
});
return id;
};
/**
* Request to Station Extension for sign and post to LCD server
*
* @param msgs transaction messages to be signed
* @param lcdClientConfig LCDClientConfig (optional)
*
* @return {string} name 'onPost'
* @return {object} payload
* @return {number} payload.id identifier
* @return {string} payload.origin origin address
* @return {Msg[]} payload.msgs requested msgs
* @return {LCDClientConfig} payload.lcdClientConfig
* requested lcdClientConfig
* @return {boolean} payload.success
* @return {number|undefined} payload.result.code
* error code. undefined with successful tx
* @return {string} payload.result.raw_log raw log
* @return {string} payload.result.txhash transaction hash
*/
Extension.prototype.post = function (msgs, lcdClientConfig) {
var id = Date.now();
var id = this.generateId();
this.send({

@@ -41,0 +97,0 @@ id: id,

12

dist/key/Key.d.ts
/// <reference types="node" />
import * as secp256k1 from 'secp256k1';
import { StdSignature } from '../core';

@@ -22,6 +21,3 @@ import { StdTx } from '../core';

*/
abstract ecdsaSign(payload: Buffer, options?: secp256k1.SignOptions): {
signature: Uint8Array;
recid: number;
};
abstract sign(payload: Buffer): Promise<Buffer>;
/**

@@ -51,8 +47,2 @@ * Terra account address. `terra-` prefixed.

/**
* Signs a data to get signature buffer using abstracted ecdsaSign method
*
* @param payload the data to be signed
*/
sign(payload: Buffer): Promise<Buffer>;
/**
* Signs a [[StdSignMsg]] with the method supplied by the child class.

@@ -59,0 +49,0 @@ *

@@ -117,20 +117,2 @@ "use strict";

/**
* Signs a data to get signature buffer using abstracted ecdsaSign method
*
* @param payload the data to be signed
*/
Key.prototype.sign = function (payload) {
return __awaiter(this, void 0, void 0, function () {
var signature;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.ecdsaSign(payload)];
case 1:
signature = (_a.sent()).signature;
return [2 /*return*/, Buffer.from(signature)];
}
});
});
};
/**
* Signs a [[StdSignMsg]] with the method supplied by the child class.

@@ -142,3 +124,3 @@ *

return __awaiter(this, void 0, void 0, function () {
var signature;
var sigBuffer;
return __generator(this, function (_a) {

@@ -148,5 +130,5 @@ switch (_a.label) {

case 1:
signature = _a.sent();
sigBuffer = _a.sent();
return [2 /*return*/, core_1.StdSignature.fromData({
signature: signature.toString('base64'),
signature: sigBuffer.toString('base64'),
pub_key: {

@@ -153,0 +135,0 @@ type: 'tendermint/PubKeySecp256k1',

/// <reference types="node" />
import * as secp256k1 from 'secp256k1';
import { Key } from './Key';

@@ -60,7 +59,8 @@ export declare const LUNA_COIN_TYPE = 330;

constructor(options?: MnemonicKeyOptions);
ecdsaSign(payload: Buffer, options?: secp256k1.SignOptions): {
ecdsaSign(payload: Buffer): {
signature: Uint8Array;
recid: number;
};
sign(payload: Buffer): Promise<Buffer>;
}
export {};

@@ -46,2 +46,38 @@ "use strict";

};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -114,6 +150,15 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

}
MnemonicKey.prototype.ecdsaSign = function (payload, options) {
MnemonicKey.prototype.ecdsaSign = function (payload) {
var hash = Buffer.from(sha256_1.default(payload.toString()).toString(), 'hex');
return secp256k1.ecdsaSign(Uint8Array.from(hash), Uint8Array.from(this.privateKey), options);
return secp256k1.ecdsaSign(Uint8Array.from(hash), Uint8Array.from(this.privateKey));
};
MnemonicKey.prototype.sign = function (payload) {
return __awaiter(this, void 0, void 0, function () {
var signature;
return __generator(this, function (_a) {
signature = this.ecdsaSign(payload).signature;
return [2 /*return*/, Buffer.from(signature)];
});
});
};
return MnemonicKey;

@@ -120,0 +165,0 @@ }(Key_1.Key));

/// <reference types="node" />
import * as secp256k1 from 'secp256k1';
import { Key } from './Key';

@@ -13,6 +12,7 @@ /**

constructor(privateKey: Buffer);
ecdsaSign(payload: Buffer, options?: secp256k1.SignOptions): {
ecdsaSign(payload: Buffer): {
signature: Uint8Array;
recid: number;
};
sign(payload: Buffer): Promise<Buffer>;
}

@@ -34,2 +34,38 @@ "use strict";

};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -55,6 +91,15 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

}
RawKey.prototype.ecdsaSign = function (payload, options) {
RawKey.prototype.ecdsaSign = function (payload) {
var hash = Buffer.from(sha256_1.default(payload.toString()).toString(), 'hex');
return secp256k1.ecdsaSign(Uint8Array.from(hash), Uint8Array.from(this.privateKey), options);
return secp256k1.ecdsaSign(Uint8Array.from(hash), Uint8Array.from(this.privateKey));
};
RawKey.prototype.sign = function (payload) {
return __awaiter(this, void 0, void 0, function () {
var signature;
return __generator(this, function (_a) {
signature = this.ecdsaSign(payload).signature;
return [2 /*return*/, Buffer.from(signature)];
});
});
};
return RawKey;

@@ -61,0 +106,0 @@ }(Key_1.Key));

{
"version": "0.4.18-beta.1",
"version": "0.4.18-beta.2",
"license": "MIT",

@@ -4,0 +4,0 @@ "main": "dist/index.js",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc