@near-js/transactions
Advanced tools
Comparing version 0.0.2 to 0.1.0
@@ -5,2 +5,4 @@ /// <reference types="node" /> | ||
import { AccessKey, Action } from './actions'; | ||
import { DelegateAction } from './delegate'; | ||
import { Signature } from './signature'; | ||
declare function fullAccessKey(): AccessKey; | ||
@@ -28,2 +30,6 @@ declare function functionCallAccessKey(receiverId: string, methodNames: string[], allowance?: BN): AccessKey; | ||
declare function deleteAccount(beneficiaryId: string): Action; | ||
declare function signedDelegate({ delegateAction, signature }: { | ||
delegateAction: DelegateAction; | ||
signature: Signature; | ||
}): Action; | ||
export declare const actionCreators: { | ||
@@ -38,2 +44,3 @@ addKey: typeof addKey; | ||
functionCallAccessKey: typeof functionCallAccessKey; | ||
signedDelegate: typeof signedDelegate; | ||
stake: typeof stake; | ||
@@ -40,0 +47,0 @@ transfer: typeof transfer; |
@@ -69,2 +69,5 @@ "use strict"; | ||
} | ||
function signedDelegate({ delegateAction, signature }) { | ||
return new actions_1.Action({ signedDelegate: new actions_1.SignedDelegate({ delegateAction, signature }) }); | ||
} | ||
exports.actionCreators = { | ||
@@ -79,4 +82,5 @@ addKey, | ||
functionCallAccessKey, | ||
signedDelegate, | ||
stake, | ||
transfer, | ||
}; |
import { PublicKey } from '@near-js/crypto'; | ||
import { Assignable } from '@near-js/types'; | ||
import BN from 'bn.js'; | ||
import { DelegateAction } from './delegate'; | ||
import { Signature } from './signature'; | ||
declare abstract class Enum { | ||
@@ -52,2 +54,6 @@ enum: string; | ||
} | ||
export declare class SignedDelegate extends IAction { | ||
delegateAction: DelegateAction; | ||
signature: Signature; | ||
} | ||
/** | ||
@@ -66,3 +72,4 @@ * Contains a list of the valid transaction Actions available with this API | ||
deleteAccount: DeleteAccount; | ||
signedDelegate: SignedDelegate; | ||
} | ||
export {}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Action = exports.DeleteAccount = exports.DeleteKey = exports.AddKey = exports.Stake = exports.Transfer = exports.FunctionCall = exports.DeployContract = exports.CreateAccount = exports.IAction = exports.AccessKey = exports.AccessKeyPermission = exports.FullAccessPermission = exports.FunctionCallPermission = void 0; | ||
exports.Action = exports.SignedDelegate = exports.DeleteAccount = exports.DeleteKey = exports.AddKey = exports.Stake = exports.Transfer = exports.FunctionCall = exports.DeployContract = exports.CreateAccount = exports.IAction = exports.AccessKey = exports.AccessKeyPermission = exports.FullAccessPermission = exports.FunctionCallPermission = void 0; | ||
const types_1 = require("@near-js/types"); | ||
@@ -55,2 +55,5 @@ class Enum { | ||
exports.DeleteAccount = DeleteAccount; | ||
class SignedDelegate extends IAction { | ||
} | ||
exports.SignedDelegate = SignedDelegate; | ||
/** | ||
@@ -57,0 +60,0 @@ * Contains a list of the valid transaction Actions available with this API |
export * from './action_creators'; | ||
export * from './actions'; | ||
export * from './create_transaction'; | ||
export * from './delegate'; | ||
export * from './schema'; | ||
export * from './sign'; | ||
export * from './signature'; |
@@ -20,3 +20,5 @@ "use strict"; | ||
__exportStar(require("./create_transaction"), exports); | ||
__exportStar(require("./delegate"), exports); | ||
__exportStar(require("./schema"), exports); | ||
__exportStar(require("./sign"), exports); | ||
__exportStar(require("./signature"), exports); |
/// <reference types="node" /> | ||
import { KeyType, PublicKey } from '@near-js/crypto'; | ||
import { PublicKey } from '@near-js/crypto'; | ||
import { Assignable } from '@near-js/types'; | ||
import BN from 'bn.js'; | ||
import { Action } from './actions'; | ||
export declare class Signature extends Assignable { | ||
keyType: KeyType; | ||
data: Uint8Array; | ||
} | ||
import { Action, SignedDelegate } from './actions'; | ||
import { DelegateAction } from './delegate'; | ||
import { Signature } from './signature'; | ||
/** | ||
* Borsh-encode a delegate action for inclusion as an action within a meta transaction | ||
* NB per NEP-461 this requires a Borsh-serialized prefix specific to delegate actions, ensuring | ||
* signed delegate actions may never be identical to signed transactions with the same fields | ||
* @param delegateAction Delegate action to be signed by the meta transaction sender | ||
*/ | ||
export declare function encodeDelegateAction(delegateAction: DelegateAction): Uint8Array; | ||
/** | ||
* Borsh-encode a signed delegate for validation and execution by a relayer | ||
* @param signedDelegate Signed delegate to be executed in a meta transaction | ||
*/ | ||
export declare function encodeSignedDelegate(signedDelegate: SignedDelegate): Uint8Array; | ||
export declare function encodeTransaction(transaction: Transaction | SignedTransaction): Uint8Array; | ||
/** | ||
* Borsh-decode a Transaction instance from a buffer | ||
* @param bytes Buffer data to be decoded | ||
*/ | ||
export declare function decodeTransaction(bytes: Buffer): Transaction; | ||
/** | ||
* Borsh-decode a SignedTransaction instance from a buffer | ||
* @param bytes Buffer data to be decoded | ||
*/ | ||
export declare function decodeSignedTransaction(bytes: Buffer): any; | ||
export declare class Transaction extends Assignable { | ||
@@ -24,6 +45,4 @@ signerId: string; | ||
encode(): Uint8Array; | ||
static decode(bytes: Buffer): SignedTransaction; | ||
static decode(bytes: Buffer): any; | ||
} | ||
type Class<T = any> = new (...args: any[]) => T; | ||
export declare const SCHEMA: Map<Class<any>, any>; | ||
export {}; | ||
export declare const SCHEMA: any; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SCHEMA = exports.SignedTransaction = exports.Transaction = exports.Signature = void 0; | ||
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"); | ||
@@ -8,11 +8,52 @@ const types_1 = require("@near-js/types"); | ||
const actions_1 = require("./actions"); | ||
class Signature extends types_1.Assignable { | ||
const delegate_1 = require("./delegate"); | ||
const prefix_1 = require("./prefix"); | ||
const signature_1 = require("./signature"); | ||
/** | ||
* Borsh-encode a delegate action for inclusion as an action within a meta transaction | ||
* NB per NEP-461 this requires a Borsh-serialized prefix specific to delegate actions, ensuring | ||
* signed delegate actions may never be identical to signed transactions with the same fields | ||
* @param delegateAction Delegate action to be signed by the meta transaction sender | ||
*/ | ||
function encodeDelegateAction(delegateAction) { | ||
return new Uint8Array([ | ||
...(0, borsh_1.serialize)(exports.SCHEMA, new prefix_1.DelegateActionPrefix()), | ||
...(0, borsh_1.serialize)(exports.SCHEMA, delegateAction), | ||
]); | ||
} | ||
exports.Signature = Signature; | ||
exports.encodeDelegateAction = encodeDelegateAction; | ||
/** | ||
* Borsh-encode a signed delegate for validation and execution by a relayer | ||
* @param signedDelegate Signed delegate to be executed in a meta transaction | ||
*/ | ||
function encodeSignedDelegate(signedDelegate) { | ||
return (0, borsh_1.serialize)(exports.SCHEMA, signedDelegate); | ||
} | ||
exports.encodeSignedDelegate = encodeSignedDelegate; | ||
function encodeTransaction(transaction) { | ||
return (0, borsh_1.serialize)(exports.SCHEMA, transaction); | ||
} | ||
exports.encodeTransaction = encodeTransaction; | ||
/** | ||
* Borsh-decode a Transaction instance from a buffer | ||
* @param bytes Buffer data to be decoded | ||
*/ | ||
function decodeTransaction(bytes) { | ||
return (0, borsh_1.deserialize)(exports.SCHEMA, Transaction, bytes); | ||
} | ||
exports.decodeTransaction = decodeTransaction; | ||
/** | ||
* Borsh-decode a SignedTransaction instance from a buffer | ||
* @param bytes Buffer data to be decoded | ||
*/ | ||
function decodeSignedTransaction(bytes) { | ||
return (0, borsh_1.deserialize)(exports.SCHEMA, SignedTransaction, bytes); | ||
} | ||
exports.decodeSignedTransaction = decodeSignedTransaction; | ||
class Transaction extends types_1.Assignable { | ||
encode() { | ||
return (0, borsh_1.serialize)(exports.SCHEMA, this); | ||
return encodeTransaction(this); | ||
} | ||
static decode(bytes) { | ||
return (0, borsh_1.deserialize)(exports.SCHEMA, Transaction, bytes); | ||
return decodeTransaction(bytes); | ||
} | ||
@@ -23,6 +64,6 @@ } | ||
encode() { | ||
return (0, borsh_1.serialize)(exports.SCHEMA, this); | ||
return encodeTransaction(this); | ||
} | ||
static decode(bytes) { | ||
return (0, borsh_1.deserialize)(exports.SCHEMA, SignedTransaction, bytes); | ||
return decodeSignedTransaction(bytes); | ||
} | ||
@@ -32,3 +73,3 @@ } | ||
exports.SCHEMA = new Map([ | ||
[Signature, { kind: 'struct', fields: [ | ||
[signature_1.Signature, { kind: 'struct', fields: [ | ||
['keyType', 'u8'], | ||
@@ -39,3 +80,3 @@ ['data', [64]] | ||
['transaction', Transaction], | ||
['signature', Signature] | ||
['signature', signature_1.Signature] | ||
] }], | ||
@@ -77,2 +118,3 @@ [Transaction, { kind: 'struct', fields: [ | ||
['deleteAccount', actions_1.DeleteAccount], | ||
['signedDelegate', actions_1.SignedDelegate], | ||
] }], | ||
@@ -106,2 +148,17 @@ [actions_1.CreateAccount, { kind: 'struct', fields: [] }], | ||
] }], | ||
[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], | ||
] }], | ||
]); |
import { Signer } from '@near-js/signers'; | ||
import BN from 'bn.js'; | ||
import { Action } from './actions'; | ||
import { Action, SignedDelegate } from './actions'; | ||
import type { DelegateAction } from './delegate'; | ||
import { SignedTransaction, Transaction } from './schema'; | ||
interface MessageSigner { | ||
sign(message: Uint8Array): Promise<Uint8Array>; | ||
} | ||
interface SignDelegateOptions { | ||
delegateAction: DelegateAction; | ||
signer: MessageSigner; | ||
} | ||
export interface SignedDelegateWithHash { | ||
hash: Uint8Array; | ||
signedDelegateAction: SignedDelegate; | ||
} | ||
export declare function signTransaction(transaction: Transaction, signer: Signer, accountId?: string, networkId?: string): Promise<[Uint8Array, SignedTransaction]>; | ||
export declare function signTransaction(receiverId: string, nonce: BN, actions: Action[], blockHash: Uint8Array, signer: Signer, accountId?: string, networkId?: string): Promise<[Uint8Array, SignedTransaction]>; | ||
/** | ||
* Sign a delegate action | ||
* @params.delegateAction Delegate action to be signed by the meta transaction sender | ||
* @params.signer Signer instance for the meta transaction sender | ||
*/ | ||
export declare function signDelegateAction({ delegateAction, signer }: SignDelegateOptions): Promise<SignedDelegateWithHash>; | ||
export {}; |
@@ -15,7 +15,8 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.signTransaction = void 0; | ||
exports.signDelegateAction = exports.signTransaction = void 0; | ||
const js_sha256_1 = __importDefault(require("js-sha256")); | ||
const borsh_1 = require("borsh"); | ||
const actions_1 = require("./actions"); | ||
const create_transaction_1 = require("./create_transaction"); | ||
const schema_1 = require("./schema"); | ||
const signature_1 = require("./signature"); | ||
/** | ||
@@ -30,3 +31,3 @@ * Signs a given transaction from an account with given keys, applied to the given network | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const message = (0, borsh_1.serialize)(schema_1.SCHEMA, transaction); | ||
const message = (0, schema_1.encodeTransaction)(transaction); | ||
const hash = new Uint8Array(js_sha256_1.default.sha256.array(message)); | ||
@@ -36,3 +37,3 @@ const signature = yield signer.signMessage(message, accountId, networkId); | ||
transaction, | ||
signature: new schema_1.Signature({ keyType: transaction.publicKey.keyType, data: signature.signature }) | ||
signature: new signature_1.Signature({ keyType: transaction.publicKey.keyType, data: signature.signature }) | ||
}); | ||
@@ -57,1 +58,24 @@ return [hash, signedTx]; | ||
exports.signTransaction = signTransaction; | ||
/** | ||
* Sign a delegate action | ||
* @params.delegateAction Delegate action to be signed by the meta transaction sender | ||
* @params.signer Signer instance for the meta transaction sender | ||
*/ | ||
function signDelegateAction({ delegateAction, signer }) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const message = (0, schema_1.encodeDelegateAction)(delegateAction); | ||
const signature = yield signer.sign(message); | ||
const signedDelegateAction = new actions_1.SignedDelegate({ | ||
delegateAction, | ||
signature: new signature_1.Signature({ | ||
keyType: delegateAction.publicKey.keyType, | ||
data: signature, | ||
}), | ||
}); | ||
return { | ||
hash: new Uint8Array(js_sha256_1.default.sha256.array(message)), | ||
signedDelegateAction, | ||
}; | ||
}); | ||
} | ||
exports.signDelegateAction = signDelegateAction; |
{ | ||
"name": "@near-js/transactions", | ||
"version": "0.0.2", | ||
"version": "0.1.0", | ||
"description": "Functions and data types for transactions on NEAR", | ||
@@ -13,6 +13,6 @@ "main": "lib/index.js", | ||
"js-sha256": "^0.9.0", | ||
"@near-js/crypto": "0.0.2", | ||
"@near-js/signers": "0.0.2", | ||
"@near-js/types": "0.0.2", | ||
"@near-js/utils": "0.0.2" | ||
"@near-js/crypto": "0.0.3", | ||
"@near-js/signers": "0.0.3", | ||
"@near-js/types": "0.0.3", | ||
"@near-js/utils": "0.0.3" | ||
}, | ||
@@ -24,3 +24,3 @@ "devDependencies": { | ||
"typescript": "^4.9.4", | ||
"@near-js/keystores": "0.0.2" | ||
"@near-js/keystores": "0.0.3" | ||
}, | ||
@@ -27,0 +27,0 @@ "files": [ |
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
33190
21
734
+ Added@near-js/crypto@0.0.3(transitive)
+ Added@near-js/keystores@0.0.3(transitive)
+ Added@near-js/signers@0.0.3(transitive)
+ Added@near-js/types@0.0.3(transitive)
+ Added@near-js/utils@0.0.3(transitive)
- Removed@near-js/crypto@0.0.2(transitive)
- Removed@near-js/keystores@0.0.2(transitive)
- Removed@near-js/signers@0.0.2(transitive)
- Removed@near-js/types@0.0.2(transitive)
- Removed@near-js/utils@0.0.2(transitive)
Updated@near-js/crypto@0.0.3
Updated@near-js/signers@0.0.3
Updated@near-js/types@0.0.3
Updated@near-js/utils@0.0.3