Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@near-js/transactions

Package Overview
Dependencies
Maintainers
2
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@near-js/transactions - npm Package Compare versions

Comparing version 0.2.1 to 1.0.0

lib/action_creators.d.ts.map

5

lib/action_creators.d.ts

@@ -23,4 +23,4 @@ /// <reference types="node" />

*/
declare function functionCall(methodName: string, args: Uint8Array | object, gas: BN, deposit: BN, stringify?: typeof stringifyJsonOrBytes, jsContract?: boolean): Action;
declare function transfer(deposit: BN): Action;
declare function functionCall(methodName: string, args: Uint8Array | object, gas?: BN, deposit?: BN, stringify?: typeof stringifyJsonOrBytes, jsContract?: boolean): Action;
declare function transfer(deposit?: BN): Action;
declare function stake(stake: BN, publicKey: PublicKey): Action;

@@ -48,1 +48,2 @@ declare function addKey(publicKey: PublicKey, accessKey: AccessKey): Action;

export {};
//# sourceMappingURL=action_creators.d.ts.map

12

lib/action_creators.js
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.actionCreators = exports.stringifyJsonOrBytes = void 0;
const bn_js_1 = __importDefault(require("bn.js"));
const actions_1 = require("./actions");
function fullAccessKey() {
return new actions_1.AccessKey({
nonce: 0,
permission: new actions_1.AccessKeyPermission({

@@ -14,2 +19,3 @@ fullAccess: new actions_1.FullAccessPermission({}),

return new actions_1.AccessKey({
nonce: 0,
permission: new actions_1.AccessKeyPermission({

@@ -42,3 +48,3 @@ functionCall: new actions_1.FunctionCallPermission({ receiverId, allowance, methodNames }),

*/
function functionCall(methodName, args, gas, deposit, stringify = stringifyJsonOrBytes, jsContract = false) {
function functionCall(methodName, args, gas = new bn_js_1.default(0), deposit = new bn_js_1.default(0), stringify = stringifyJsonOrBytes, jsContract = false) {
if (jsContract) {

@@ -56,6 +62,6 @@ return new actions_1.Action({ functionCall: new actions_1.FunctionCall({ methodName, args, gas, deposit }) });

}
function transfer(deposit) {
function transfer(deposit = new bn_js_1.default(0)) {
return new actions_1.Action({ transfer: new actions_1.Transfer({ deposit }) });
}
function stake(stake, publicKey) {
function stake(stake = new bn_js_1.default(0), publicKey) {
return new actions_1.Action({ stake: new actions_1.Stake({ stake, publicKey }) });

@@ -62,0 +68,0 @@ }

@@ -22,2 +22,3 @@ import { PublicKey } from '@near-js/crypto';

export declare class AccessKey extends Assignable {
nonce: BN;
permission: AccessKeyPermission;

@@ -75,1 +76,2 @@ }

export {};
//# sourceMappingURL=actions.d.ts.map

@@ -6,1 +6,2 @@ import { PublicKey } from '@near-js/crypto';

export declare function createTransaction(signerId: string, publicKey: PublicKey, receiverId: string, nonce: BN | string | number, actions: Action[], blockHash: Uint8Array): Transaction;
//# sourceMappingURL=create_transaction.d.ts.map
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createTransaction = void 0;
const bn_js_1 = __importDefault(require("bn.js"));
const schema_1 = require("./schema");
function createTransaction(signerId, publicKey, receiverId, nonce, actions, blockHash) {
return new schema_1.Transaction({ signerId, publicKey, nonce, receiverId, actions, blockHash });
return new schema_1.Transaction({ signerId, publicKey, nonce: new bn_js_1.default(nonce), receiverId, actions, blockHash });
}
exports.createTransaction = createTransaction;

@@ -23,1 +23,2 @@ import { PublicKey } from '@near-js/crypto';

export declare function buildDelegateAction({ actions, maxBlockHeight, nonce, publicKey, receiverId, senderId, }: DelegateAction): DelegateAction;
//# sourceMappingURL=delegate.d.ts.map

@@ -8,1 +8,2 @@ export * from './action_creators';

export * from './signature';
//# sourceMappingURL=index.d.ts.map

@@ -20,1 +20,2 @@ import { Assignable } from '@near-js/types';

export {};
//# sourceMappingURL=prefix.d.ts.map

@@ -1,4 +0,4 @@

/// <reference types="node" />
import { PublicKey } from '@near-js/crypto';
import { Assignable } from '@near-js/types';
import { Schema } from 'borsh';
import BN from 'bn.js';

@@ -23,10 +23,10 @@ import { Action, SignedDelegate } from './actions';

* Borsh-decode a Transaction instance from a buffer
* @param bytes Buffer data to be decoded
* @param bytes Uint8Array data to be decoded
*/
export declare function decodeTransaction(bytes: Buffer): Transaction;
export declare function decodeTransaction(bytes: Uint8Array): Transaction;
/**
* Borsh-decode a SignedTransaction instance from a buffer
* @param bytes Buffer data to be decoded
* @param bytes Uint8Array data to be decoded
*/
export declare function decodeSignedTransaction(bytes: Buffer): any;
export declare function decodeSignedTransaction(bytes: Uint8Array): SignedTransaction;
export declare class Transaction extends Assignable {

@@ -40,3 +40,3 @@ signerId: string;

encode(): Uint8Array;
static decode(bytes: Buffer): Transaction;
static decode(bytes: Uint8Array): Transaction;
}

@@ -47,4 +47,27 @@ export declare class SignedTransaction extends Assignable {

encode(): Uint8Array;
static decode(bytes: Buffer): any;
static decode(bytes: Uint8Array): SignedTransaction;
}
export declare const SCHEMA: any;
export declare const SCHEMA: {
Signature: Schema;
PublicKey: Schema;
FunctionCallPermission: Schema;
FullAccessPermission: Schema;
AccessKeyPermission: Schema;
AccessKey: Schema;
CreateAccount: Schema;
DeployContract: Schema;
FunctionCall: Schema;
Transfer: Schema;
Stake: Schema;
AddKey: Schema;
DeleteKey: Schema;
DeleteAccount: Schema;
DelegateActionPrefix: Schema;
ClassicActions: Schema;
DelegateAction: Schema;
SignedDelegate: Schema;
Action: Schema;
Transaction: Schema;
SignedTransaction: Schema;
};
//# sourceMappingURL=schema.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SCHEMA = exports.SignedTransaction = exports.Transaction = exports.decodeSignedTransaction = exports.decodeTransaction = exports.encodeTransaction = exports.encodeSignedDelegate = exports.encodeDelegateAction = void 0;
const crypto_1 = require("@near-js/crypto");
const types_1 = require("@near-js/types");
const borsh_1 = require("borsh");
const actions_1 = require("./actions");
const delegate_1 = require("./delegate");
const prefix_1 = require("./prefix");
const signature_1 = require("./signature");
/**

@@ -19,4 +15,4 @@ * Borsh-encode a delegate action for inclusion as an action within a meta transaction

return new Uint8Array([
...(0, borsh_1.serialize)(exports.SCHEMA, new prefix_1.DelegateActionPrefix()),
...(0, borsh_1.serialize)(exports.SCHEMA, delegateAction),
...(0, borsh_1.serialize)(exports.SCHEMA.DelegateActionPrefix, new prefix_1.DelegateActionPrefix()),
...(0, borsh_1.serialize)(exports.SCHEMA.DelegateAction, delegateAction),
]);

@@ -30,7 +26,8 @@ }

function encodeSignedDelegate(signedDelegate) {
return (0, borsh_1.serialize)(exports.SCHEMA, signedDelegate);
return (0, borsh_1.serialize)(exports.SCHEMA.SignedDelegate, signedDelegate);
}
exports.encodeSignedDelegate = encodeSignedDelegate;
function encodeTransaction(transaction) {
return (0, borsh_1.serialize)(exports.SCHEMA, transaction);
const schema = transaction instanceof SignedTransaction ? exports.SCHEMA.SignedTransaction : exports.SCHEMA.Transaction;
return (0, borsh_1.serialize)(schema, transaction);
}

@@ -40,6 +37,6 @@ exports.encodeTransaction = encodeTransaction;

* Borsh-decode a Transaction instance from a buffer
* @param bytes Buffer data to be decoded
* @param bytes Uint8Array data to be decoded
*/
function decodeTransaction(bytes) {
return (0, borsh_1.deserialize)(exports.SCHEMA, Transaction, bytes);
return new Transaction((0, borsh_1.deserialize)(exports.SCHEMA.Transaction, bytes));
}

@@ -49,6 +46,6 @@ exports.decodeTransaction = decodeTransaction;

* Borsh-decode a SignedTransaction instance from a buffer
* @param bytes Buffer data to be decoded
* @param bytes Uint8Array data to be decoded
*/
function decodeSignedTransaction(bytes) {
return (0, borsh_1.deserialize)(exports.SCHEMA, SignedTransaction, bytes);
return new SignedTransaction((0, borsh_1.deserialize)(exports.SCHEMA.SignedTransaction, bytes));
}

@@ -74,90 +71,144 @@ exports.decodeSignedTransaction = decodeSignedTransaction;

exports.SignedTransaction = SignedTransaction;
exports.SCHEMA = new Map([
[signature_1.Signature, { kind: 'struct', fields: [
['keyType', 'u8'],
['data', [64]]
] }],
[SignedTransaction, { kind: 'struct', fields: [
['transaction', Transaction],
['signature', signature_1.Signature]
] }],
[Transaction, { kind: 'struct', fields: [
['signerId', 'string'],
['publicKey', crypto_1.PublicKey],
['nonce', 'u64'],
['receiverId', 'string'],
['blockHash', [32]],
['actions', [actions_1.Action]]
] }],
[crypto_1.PublicKey, { kind: 'struct', fields: [
['keyType', 'u8'],
['data', [32]]
] }],
[actions_1.AccessKey, { kind: 'struct', fields: [
['nonce', 'u64'],
['permission', actions_1.AccessKeyPermission],
] }],
[actions_1.AccessKeyPermission, { kind: 'enum', field: 'enum', values: [
['functionCall', actions_1.FunctionCallPermission],
['fullAccess', actions_1.FullAccessPermission],
] }],
[actions_1.FunctionCallPermission, { kind: 'struct', fields: [
['allowance', { kind: 'option', type: 'u128' }],
['receiverId', 'string'],
['methodNames', ['string']],
] }],
[actions_1.FullAccessPermission, { kind: 'struct', fields: [] }],
[actions_1.Action, { kind: 'enum', field: 'enum', values: [
['createAccount', actions_1.CreateAccount],
['deployContract', actions_1.DeployContract],
['functionCall', actions_1.FunctionCall],
['transfer', actions_1.Transfer],
['stake', actions_1.Stake],
['addKey', actions_1.AddKey],
['deleteKey', actions_1.DeleteKey],
['deleteAccount', actions_1.DeleteAccount],
['signedDelegate', actions_1.SignedDelegate],
] }],
[actions_1.CreateAccount, { kind: 'struct', fields: [] }],
[actions_1.DeployContract, { kind: 'struct', fields: [
['code', ['u8']]
] }],
[actions_1.FunctionCall, { kind: 'struct', fields: [
['methodName', 'string'],
['args', ['u8']],
['gas', 'u64'],
['deposit', 'u128']
] }],
[actions_1.Transfer, { kind: 'struct', fields: [
['deposit', 'u128']
] }],
[actions_1.Stake, { kind: 'struct', fields: [
['stake', 'u128'],
['publicKey', crypto_1.PublicKey]
] }],
[actions_1.AddKey, { kind: 'struct', fields: [
['publicKey', crypto_1.PublicKey],
['accessKey', actions_1.AccessKey]
] }],
[actions_1.DeleteKey, { kind: 'struct', fields: [
['publicKey', crypto_1.PublicKey]
] }],
[actions_1.DeleteAccount, { kind: 'struct', fields: [
['beneficiaryId', 'string']
] }],
[delegate_1.DelegateAction, { kind: 'struct', fields: [
['senderId', 'string'],
['receiverId', 'string'],
['actions', [actions_1.Action]],
['nonce', 'u64'],
['maxBlockHeight', 'u64'],
['publicKey', crypto_1.PublicKey],
] }],
[prefix_1.DelegateActionPrefix, { kind: 'struct', fields: [
['prefix', 'u32'],
] }],
[actions_1.SignedDelegate, { kind: 'struct', fields: [
['delegateAction', delegate_1.DelegateAction],
['signature', signature_1.Signature],
] }],
]);
exports.SCHEMA = new class BorshSchema {
constructor() {
this.Signature = {
struct: {
keyType: 'u8',
data: { array: { type: 'u8', len: 64 } },
}
};
this.PublicKey = {
struct: {
keyType: 'u8',
data: { array: { type: 'u8', len: 32 } },
}
};
this.FunctionCallPermission = {
struct: {
allowance: { option: 'u128' },
receiverId: 'string',
methodNames: { array: { type: 'string' } },
}
};
this.FullAccessPermission = {
struct: {}
};
this.AccessKeyPermission = {
enum: [
{ struct: { functionCall: this.FunctionCallPermission } },
{ struct: { fullAccess: this.FullAccessPermission } },
]
};
this.AccessKey = {
struct: {
nonce: 'u64',
permission: this.AccessKeyPermission,
}
};
this.CreateAccount = {
struct: {}
};
this.DeployContract = {
struct: {
code: { array: { type: 'u8' } },
}
};
this.FunctionCall = {
struct: {
methodName: 'string',
args: { array: { type: 'u8' } },
gas: 'u64',
deposit: 'u128',
}
};
this.Transfer = {
struct: {
deposit: 'u128',
}
};
this.Stake = {
struct: {
stake: 'u128',
publicKey: this.PublicKey,
}
};
this.AddKey = {
struct: {
publicKey: this.PublicKey,
accessKey: this.AccessKey,
}
};
this.DeleteKey = {
struct: {
publicKey: this.PublicKey,
}
};
this.DeleteAccount = {
struct: {
beneficiaryId: 'string',
}
};
this.DelegateActionPrefix = {
struct: {
prefix: 'u32',
}
};
this.ClassicActions = {
enum: [
{ struct: { createAccount: this.CreateAccount } },
{ struct: { deployContract: this.DeployContract } },
{ struct: { functionCall: this.FunctionCall } },
{ struct: { transfer: this.Transfer } },
{ struct: { stake: this.Stake } },
{ struct: { addKey: this.AddKey } },
{ struct: { deleteKey: this.DeleteKey } },
{ struct: { deleteAccount: this.DeleteAccount } },
]
};
this.DelegateAction = {
struct: {
senderId: 'string',
receiverId: 'string',
nonce: 'u64',
actions: { array: { type: this.ClassicActions } },
maxBlockHeight: 'u64',
publicKey: this.PublicKey,
}
};
this.SignedDelegate = {
struct: {
delegateAction: this.DelegateAction,
signature: this.Signature,
}
};
this.Action = {
enum: [
{ struct: { createAccount: this.CreateAccount } },
{ struct: { deployContract: this.DeployContract } },
{ struct: { functionCall: this.FunctionCall } },
{ struct: { transfer: this.Transfer } },
{ struct: { stake: this.Stake } },
{ struct: { addKey: this.AddKey } },
{ struct: { deleteKey: this.DeleteKey } },
{ struct: { deleteAccount: this.DeleteAccount } },
{ struct: { signedDelegate: this.SignedDelegate } },
]
};
this.Transaction = {
struct: {
signerId: 'string',
publicKey: this.PublicKey,
nonce: 'u64',
receiverId: 'string',
blockHash: { array: { type: 'u8', len: 32 } },
actions: { array: { type: this.Action } },
}
};
this.SignedTransaction = {
struct: {
transaction: this.Transaction,
signature: this.Signature,
}
};
}
};

@@ -26,1 +26,2 @@ import { Signer } from '@near-js/signers';

export {};
//# sourceMappingURL=sign.d.ts.map

@@ -7,1 +7,2 @@ import { KeyType } from '@near-js/crypto';

}
//# sourceMappingURL=signature.d.ts.map
{
"name": "@near-js/transactions",
"version": "0.2.1",
"version": "1.0.0",
"description": "Functions and data types for transactions on NEAR",

@@ -11,15 +11,15 @@ "main": "lib/index.js",

"bn.js": "5.2.1",
"borsh": "^0.7.0",
"js-sha256": "^0.9.0",
"@near-js/crypto": "0.0.5",
"@near-js/signers": "0.0.5",
"borsh": "1.0.0",
"js-sha256": "0.9.0",
"@near-js/crypto": "1.0.0",
"@near-js/signers": "0.0.6",
"@near-js/types": "0.0.4",
"@near-js/utils": "0.0.4"
"@near-js/utils": "0.0.5"
},
"devDependencies": {
"@types/node": "^18.11.18",
"jest": "^26.0.1",
"ts-jest": "^26.5.6",
"typescript": "^4.9.4",
"@near-js/keystores": "0.0.5"
"@types/node": "18.11.18",
"jest": "26.0.1",
"ts-jest": "26.5.6",
"typescript": "4.9.4",
"@near-js/keystores": "0.0.6"
},

@@ -26,0 +26,0 @@ "files": [

@@ -7,7 +7,7 @@ # @near-js/transactions

- [actionCreators](src/action_creators.ts) functions for composing actions
- [Actions](src/actions.ts) classes for actions
- [Schema](src/schema.ts) classes and types concerned with (de-)serialization of transactions
- [createTransaction](src/create_transaction.ts) function for composing a transaction
- [signTransaction](src/sign.ts) function for signing a transaction
- [actionCreators](https://github.com/near/near-api-js/blob/master/packages/transactions/src/action_creators.ts) functions for composing actions
- [Actions](https://github.com/near/near-api-js/blob/master/packages/transactions/src/actions.ts) classes for actions
- [Schema](https://github.com/near/near-api-js/blob/master/packages/transactions/src/schema.ts) classes and types concerned with (de-)serialization of transactions
- [createTransaction](https://github.com/near/near-api-js/blob/master/packages/transactions/src/create_transaction.ts) function for composing a transaction
- [signTransaction](https://github.com/near/near-api-js/blob/master/packages/transactions/src/sign.ts) function for signing a transaction

@@ -14,0 +14,0 @@ # License

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc