@iota/bundle
Advanced tools
Comparing version 1.0.0-alpha.1 to 1.0.0-alpha.42086419
"use strict"; | ||
/** @module bundle */ | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
exports.__esModule = true; | ||
var bundle_1 = require("./bundle"); | ||
exports.createBundle = bundle_1.createBundle; | ||
exports.addEntry = bundle_1.addEntry; | ||
exports.addTrytes = bundle_1.addTrytes; | ||
exports.finalizeBundle = bundle_1.finalizeBundle; | ||
var converter_1 = require("@iota/converter"); | ||
var kerl_1 = require("@iota/kerl"); | ||
var pad_1 = require("@iota/pad"); | ||
var signing_1 = require("@iota/signing"); | ||
require("../../typed-array"); | ||
var NULL_HASH_TRYTES = '9'.repeat(81); | ||
var NULL_TAG_TRYTES = '9'.repeat(27); | ||
var NULL_NONCE_TRYTES = '9'.repeat(27); | ||
var NULL_SIGNATURE_MESSAGE_FRAGMENT_TRYTES = '9'.repeat(2187); | ||
var getEntryWithDefaults = function (entry) { return ({ | ||
length: entry.length || 1, | ||
address: entry.address || NULL_HASH_TRYTES, | ||
value: entry.value || 0, | ||
tag: entry.tag || NULL_TAG_TRYTES, | ||
timestamp: entry.timestamp || Math.floor(Date.now() / 1000), | ||
signatureMessageFragments: entry.signatureMessageFragments | ||
? entry.signatureMessageFragments.map(pad_1.padTrytes(2187)) | ||
: Array(entry.length || 1).fill(NULL_SIGNATURE_MESSAGE_FRAGMENT_TRYTES) | ||
}); }; | ||
/** | ||
* Creates a bundle with given transaction entries. | ||
* | ||
* @method createBundle | ||
* | ||
* @param {BundleEntry[]} entries - Entries of single or multiple transactions with the same address | ||
* | ||
* @return {Transaction[]} List of transactions in the bundle | ||
*/ | ||
exports.createBundle = function (entries) { | ||
if (entries === void 0) { entries = []; } | ||
return entries.reduce(function (bundle, entry) { return exports.addEntry(bundle, entry); }, []); | ||
}; | ||
/** | ||
* Adds given transaction entry to a bundle. | ||
* | ||
* @method addEntry | ||
* | ||
* @param {Transaction[]} transactions - List of transactions currently in the bundle | ||
* | ||
* @param {object} entry - Entry of a single or multiple transactions with the same address | ||
* @param {number} [entry.length = 1] - Entry length, which indicates how many transactions in the bundle it will occupy | ||
* @param {Hash} [entry.address] - Address, defaults to all-9s | ||
* @param {number} [entry.value = 0] - Value to transfer in iotas | ||
* @param {Trytes[]} [entry.signatureMessageFragments] - List of signature message fragments, defaults to all-9s | ||
* @param {number} [entry.timestamp] - Transaction timestamp, defaults to `Math.floor(Date.now() / 1000)` | ||
* @param {string} [entry.tag] - Optional Tag, defaults to null tag (all-9s) | ||
* | ||
* @return {Transaction[]} List of transactions in the updated bundle | ||
*/ | ||
exports.addEntry = function (transactions, entry) { | ||
var entryWithDefaults = getEntryWithDefaults(entry); | ||
var length = entryWithDefaults.length, address = entryWithDefaults.address, value = entryWithDefaults.value, timestamp = entryWithDefaults.timestamp, signatureMessageFragments = entryWithDefaults.signatureMessageFragments; | ||
var lastIndex = transactions.length - 1 + length; | ||
var tag = pad_1.padTag(entryWithDefaults.tag); | ||
var obsoleteTag = tag; | ||
return transactions.map(function (transaction) { return (__assign({}, transaction, { lastIndex: lastIndex })); }).concat(Array(length) | ||
.fill(null) | ||
.map(function (_, i) { return ({ | ||
address: address, | ||
value: i === 0 ? value : 0, | ||
tag: tag, | ||
obsoleteTag: obsoleteTag, | ||
currentIndex: transactions.length + i, | ||
lastIndex: lastIndex, | ||
timestamp: timestamp, | ||
signatureMessageFragment: signatureMessageFragments[i], | ||
trunkTransaction: NULL_HASH_TRYTES, | ||
branchTransaction: NULL_HASH_TRYTES, | ||
attachmentTimestamp: 0, | ||
attachmentTimestampLowerBound: 0, | ||
attachmentTimestampUpperBound: 0, | ||
bundle: NULL_HASH_TRYTES, | ||
nonce: NULL_NONCE_TRYTES, | ||
hash: NULL_HASH_TRYTES | ||
}); })); | ||
}; | ||
/** | ||
* Adds signature message fragments to transactions in a bundle starting at offset. | ||
* | ||
* @method addTrytes | ||
* | ||
* @param {Transaction[]} transactions - List of transactions in the bundle | ||
* | ||
* @param {Trytes[]} fragments - List of signature message fragments to add | ||
* | ||
* @param {number} [offset = 0] - Optional offset to start appending signature message fragments | ||
* | ||
* @return {Transaction[]} List of transactions in the updated bundle | ||
*/ | ||
exports.addTrytes = function (transactions, fragments, offset) { | ||
if (offset === void 0) { offset = 0; } | ||
return transactions.map(function (transaction, i) { | ||
return i >= offset && i < offset + fragments.length | ||
? __assign({}, transaction, { signatureMessageFragment: pad_1.padTrytes(27 * 81)(fragments[i - offset] || '') }) : transaction; | ||
}); | ||
}; | ||
/** | ||
* Finalizes a bundle by calculating the bundle hash. | ||
* | ||
* @method finalizeBundle | ||
* | ||
* @param {Transaction[]} transactions - List of transactions in the bundle | ||
* | ||
* @return {Transaction[]} List of transactions in the finalized bundle | ||
*/ | ||
exports.finalizeBundle = function (transactions) { | ||
var validBundle = false; | ||
var valueTrits = transactions.map(function (tx) { return converter_1.trits(tx.value); }).map(pad_1.padTrits(81)); | ||
var timestampTrits = transactions.map(function (tx) { return converter_1.trits(tx.timestamp); }).map(pad_1.padTrits(27)); | ||
var currentIndexTrits = transactions.map(function (tx) { return converter_1.trits(tx.currentIndex); }).map(pad_1.padTrits(27)); | ||
var lastIndexTrits = pad_1.padTrits(27)(converter_1.trits(transactions[0].lastIndex)); | ||
var obsoleteTagTrits = transactions.map(function (tx) { return converter_1.trits(tx.obsoleteTag); }).map(pad_1.padTrits(81)); | ||
var bundleHashTrits = new Int8Array(kerl_1["default"].HASH_LENGTH); | ||
while (!validBundle) { | ||
var sponge = new kerl_1["default"](); | ||
for (var i = 0; i < transactions.length; i++) { | ||
var essence = converter_1.trits(transactions[i].address + | ||
converter_1.trytes(valueTrits[i]) + | ||
converter_1.trytes(obsoleteTagTrits[i]) + | ||
converter_1.trytes(timestampTrits[i]) + | ||
converter_1.trytes(currentIndexTrits[i]) + | ||
converter_1.trytes(lastIndexTrits)); | ||
sponge.absorb(essence, 0, essence.length); | ||
} | ||
sponge.squeeze(bundleHashTrits, 0, kerl_1["default"].HASH_LENGTH); | ||
if (signing_1.normalizedBundle(bundleHashTrits).indexOf(13) !== -1) { | ||
// Insecure bundle, increment obsoleteTag and recompute bundle hash | ||
obsoleteTagTrits[0] = signing_1.add(obsoleteTagTrits[0], new Int8Array(1).fill(1)); | ||
} | ||
else { | ||
validBundle = true; | ||
} | ||
} | ||
return transactions.map(function (transaction, i) { return (__assign({}, transaction, { | ||
// overwrite obsoleteTag in first entry | ||
obsoleteTag: i === 0 ? converter_1.trytes(obsoleteTagTrits[0]) : transaction.obsoleteTag, bundle: converter_1.trytes(bundleHashTrits) })); }); | ||
}; | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
var __assign = (this && this.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
exports.__esModule = true; | ||
var ava_1 = require("ava"); | ||
var bundle_1 = require("../src/bundle"); | ||
var src_1 = require("../src"); | ||
var NULL_HASH = '9'.repeat(81); | ||
@@ -74,3 +77,3 @@ var NULL_NONCE = '9'.repeat(27); | ||
ava_1["default"]('createBundle() returns correct transactions.', function (t) { | ||
t.deepEqual(bundle_1.createBundle([ | ||
t.deepEqual(src_1.createBundle([ | ||
{ | ||
@@ -93,3 +96,3 @@ length: 2, | ||
ava_1["default"]('addEntry() adds new entry and returns correct transactions.', function (t) { | ||
t.deepEqual(bundle_1.addEntry(bundle.slice(0, 2), { | ||
t.deepEqual(src_1.addEntry(bundle.slice(0, 2), { | ||
length: 1, | ||
@@ -103,3 +106,3 @@ address: addresses[1], | ||
ava_1["default"]('addTrytes() adds trytes and returns correct transactions.', function (t) { | ||
t.deepEqual(bundle_1.addTrytes(bundle, ['TRYTES', 'TRYTES', 'TRYTES']), bundle.map(function (transaction) { return (__assign({}, transaction, { signatureMessageFragment: 'TRYTES' + '9'.repeat(81 * 27 - 6) })); }), 'addEntry should add trytes and return correct transactions.'); | ||
t.deepEqual(src_1.addTrytes(bundle, ['TRYTES', 'TRYTES', 'TRYTES']), bundle.map(function (transaction) { return (__assign({}, transaction, { signatureMessageFragment: 'TRYTES' + '9'.repeat(81 * 27 - 6) })); }), 'addEntry should add trytes and return correct transactions.'); | ||
}); | ||
@@ -110,4 +113,4 @@ ava_1["default"]('finalizeBundle() adds correct bundle hash.', function (t) { | ||
var expected = bundle.map(function (transaction, i) { return (__assign({}, transaction, { obsoleteTag: i === 0 ? incrObsoleteTag : transaction.obsoleteTag, bundle: bundleHash })); }); | ||
t.deepEqual(bundle_1.finalizeBundle(bundle), expected, 'finalizeBundle() should add correct bundle hash.'); | ||
t.deepEqual(src_1.finalizeBundle(bundle), expected, 'finalizeBundle() should add correct bundle hash.'); | ||
}); | ||
//# sourceMappingURL=bundle.test.js.map |
{ | ||
"name": "@iota/bundle", | ||
"version": "1.0.0-alpha.1", | ||
"version": "1.0.0-alpha.42086419", | ||
"description": "Utilities for generating and signing bundles", | ||
@@ -11,6 +11,6 @@ "main": "./out/bundle/src/index.js", | ||
"scripts": { | ||
"prepublish": "tsc", | ||
"prepare": "tsc", | ||
"test": "tsc && nyc ava", | ||
"test-ci": "nyc ava", | ||
"format": "prettier", | ||
"lint": "tslint --project .", | ||
"docs": "tsc && jsdoc2md --no-cache --plugin dmd-clear -t README_tpl.hbs --files './out/**/*.js' > README.md" | ||
@@ -68,7 +68,7 @@ }, | ||
"dependencies": { | ||
"@iota/converter": "^1.0.0-alpha.1", | ||
"@iota/kerl": "^1.0.0-alpha.1", | ||
"@iota/pad": "^1.0.0-alpha.1", | ||
"@iota/signing": "^1.0.0-alpha.1" | ||
"@iota/converter": "^1.0.0-alpha.42086419", | ||
"@iota/kerl": "^1.0.0-alpha.42086419", | ||
"@iota/pad": "^1.0.0-alpha.42086419", | ||
"@iota/signing": "^1.0.0-alpha.42086419" | ||
} | ||
} |
@@ -39,5 +39,5 @@ # @iota/bundle | ||
| --- | --- | --- | | ||
| entries | <code>Array.<BundleEntry></code> | Entries of signle or multiple transactions with the same address | | ||
| entries | <code>Array.<BundleEntry></code> | Entries of single or multiple transactions with the same address | | ||
Creates a bunlde with given transaction entries. | ||
Creates a bundle with given transaction entries. | ||
@@ -52,13 +52,13 @@ **Returns**: <code>Array.<Transaction></code> - List of transactions in the bundle | ||
| transactions | <code>Array.<Transaction></code> | | List of transactions currently in the bundle | | ||
| entry | <code>object</code> | | Entry of single or multiple transactions with the same address | | ||
| [entry.length] | <code>number</code> | <code>1</code> | Entry length, which indicates how many transactions in the bundle will occupy | | ||
| [entry.address] | <code>string</code> | | Address, defaults to all-9s | | ||
| [entry.value] | <code>number</code> | <code>0</code> | Value to transfer in _IOTAs_ | | ||
| [entry.signatureMessageFragments] | <code>Array.<string></code> | | Array of signature message fragments trytes, defaults to all-9s | | ||
| entry | <code>object</code> | | Entry of a single or multiple transactions with the same address | | ||
| [entry.length] | <code>number</code> | <code>1</code> | Entry length, which indicates how many transactions in the bundle it will occupy | | ||
| [entry.address] | <code>Hash</code> | | Address, defaults to all-9s | | ||
| [entry.value] | <code>number</code> | <code>0</code> | Value to transfer in iotas | | ||
| [entry.signatureMessageFragments] | <code>Array.<Trytes></code> | | List of signature message fragments, defaults to all-9s | | ||
| [entry.timestamp] | <code>number</code> | | Transaction timestamp, defaults to `Math.floor(Date.now() / 1000)` | | ||
| [entry.tag] | <code>string</code> | | Optional Tag, defaults to null tag (all-9s) | | ||
Creates a bunlde with given transaction entries | ||
Adds given transaction entry to a bundle. | ||
**Returns**: <code>Array.<Transaction></code> - Bundle | ||
**Returns**: <code>Array.<Transaction></code> - List of transactions in the updated bundle | ||
<a name="module_bundle..addTrytes"></a> | ||
@@ -70,9 +70,9 @@ | ||
| --- | --- | --- | --- | | ||
| transactions | <code>Array.<Transaction></code> | | Transactions in the bundle | | ||
| fragments | <code>Array.<Trytes></code> | | Message signature fragments to add | | ||
| transactions | <code>Array.<Transaction></code> | | List of transactions in the bundle | | ||
| fragments | <code>Array.<Trytes></code> | | List of signature message fragments to add | | ||
| [offset] | <code>number</code> | <code>0</code> | Optional offset to start appending signature message fragments | | ||
Adds a list of trytes in the bundle starting at offset | ||
Adds signature message fragments to transactions in a bundle starting at offset. | ||
**Returns**: <code>Array.<Transaction></code> - Transactions of finalized bundle | ||
**Returns**: <code>Array.<Transaction></code> - List of transactions in the updated bundle | ||
<a name="module_bundle..finalizeBundle"></a> | ||
@@ -84,6 +84,6 @@ | ||
| --- | --- | --- | | ||
| transactions | <code>Array.<Transaction></code> | Transactions in the bundle | | ||
| transactions | <code>Array.<Transaction></code> | List of transactions in the bundle | | ||
Finalizes the bundle by calculating the bundle hash | ||
Finalizes a bundle by calculating the bundle hash. | ||
**Returns**: <code>Array.<Transaction></code> - Transactions of finalized bundle | ||
**Returns**: <code>Array.<Transaction></code> - List of transactions in the finalized bundle |
177
src/index.ts
@@ -1,1 +0,176 @@ | ||
export { BundleEntry, createBundle, addEntry, addTrytes, finalizeBundle } from './bundle' | ||
/** @module bundle */ | ||
import { trits, trytes } from '@iota/converter' | ||
import Kerl from '@iota/kerl' | ||
import { padTag, padTrits, padTrytes } from '@iota/pad' | ||
import { add, normalizedBundle } from '@iota/signing' | ||
import '../../typed-array' | ||
import { | ||
Bundle, | ||
Hash, | ||
Transaction, // tslint:disable-line no-unused-variable | ||
Trytes, | ||
} from '../../types' | ||
const NULL_HASH_TRYTES = '9'.repeat(81) | ||
const NULL_TAG_TRYTES = '9'.repeat(27) | ||
const NULL_NONCE_TRYTES = '9'.repeat(27) | ||
const NULL_SIGNATURE_MESSAGE_FRAGMENT_TRYTES = '9'.repeat(2187) | ||
export interface BundleEntry { | ||
readonly length: number | ||
readonly address: Hash | ||
readonly value: number | ||
readonly tag: string | ||
readonly timestamp: number | ||
readonly signatureMessageFragments: ReadonlyArray<Trytes> | ||
} | ||
export { Transaction, Bundle } | ||
const getEntryWithDefaults = (entry: Partial<BundleEntry>): BundleEntry => ({ | ||
length: entry.length || 1, | ||
address: entry.address || NULL_HASH_TRYTES, | ||
value: entry.value || 0, | ||
tag: entry.tag || NULL_TAG_TRYTES, | ||
timestamp: entry.timestamp || Math.floor(Date.now() / 1000), | ||
signatureMessageFragments: entry.signatureMessageFragments | ||
? entry.signatureMessageFragments.map(padTrytes(2187)) | ||
: Array(entry.length || 1).fill(NULL_SIGNATURE_MESSAGE_FRAGMENT_TRYTES), | ||
}) | ||
/** | ||
* Creates a bundle with given transaction entries. | ||
* | ||
* @method createBundle | ||
* | ||
* @param {BundleEntry[]} entries - Entries of single or multiple transactions with the same address | ||
* | ||
* @return {Transaction[]} List of transactions in the bundle | ||
*/ | ||
export const createBundle = (entries: ReadonlyArray<Partial<BundleEntry>> = []): Bundle => | ||
entries.reduce((bundle: Bundle, entry) => addEntry(bundle, entry), []) | ||
/** | ||
* Adds given transaction entry to a bundle. | ||
* | ||
* @method addEntry | ||
* | ||
* @param {Transaction[]} transactions - List of transactions currently in the bundle | ||
* | ||
* @param {object} entry - Entry of a single or multiple transactions with the same address | ||
* @param {number} [entry.length = 1] - Entry length, which indicates how many transactions in the bundle it will occupy | ||
* @param {Hash} [entry.address] - Address, defaults to all-9s | ||
* @param {number} [entry.value = 0] - Value to transfer in iotas | ||
* @param {Trytes[]} [entry.signatureMessageFragments] - List of signature message fragments, defaults to all-9s | ||
* @param {number} [entry.timestamp] - Transaction timestamp, defaults to `Math.floor(Date.now() / 1000)` | ||
* @param {string} [entry.tag] - Optional Tag, defaults to null tag (all-9s) | ||
* | ||
* @return {Transaction[]} List of transactions in the updated bundle | ||
*/ | ||
export const addEntry = (transactions: Bundle, entry: Partial<BundleEntry>): Bundle => { | ||
const entryWithDefaults = getEntryWithDefaults(entry) | ||
const { length, address, value, timestamp, signatureMessageFragments } = entryWithDefaults | ||
const lastIndex = transactions.length - 1 + length | ||
const tag = padTag(entryWithDefaults.tag) | ||
const obsoleteTag = tag | ||
return transactions.map(transaction => ({ ...transaction, lastIndex })).concat( | ||
Array(length) | ||
.fill(null) | ||
.map((_, i) => ({ | ||
address, | ||
value: i === 0 ? value : 0, | ||
tag, | ||
obsoleteTag, | ||
currentIndex: transactions.length + i, | ||
lastIndex, | ||
timestamp, | ||
signatureMessageFragment: signatureMessageFragments[i], | ||
trunkTransaction: NULL_HASH_TRYTES, | ||
branchTransaction: NULL_HASH_TRYTES, | ||
attachmentTimestamp: 0, | ||
attachmentTimestampLowerBound: 0, | ||
attachmentTimestampUpperBound: 0, | ||
bundle: NULL_HASH_TRYTES, | ||
nonce: NULL_NONCE_TRYTES, | ||
hash: NULL_HASH_TRYTES, | ||
})) | ||
) | ||
} | ||
/** | ||
* Adds signature message fragments to transactions in a bundle starting at offset. | ||
* | ||
* @method addTrytes | ||
* | ||
* @param {Transaction[]} transactions - List of transactions in the bundle | ||
* | ||
* @param {Trytes[]} fragments - List of signature message fragments to add | ||
* | ||
* @param {number} [offset = 0] - Optional offset to start appending signature message fragments | ||
* | ||
* @return {Transaction[]} List of transactions in the updated bundle | ||
*/ | ||
export const addTrytes = (transactions: Bundle, fragments: ReadonlyArray<Trytes>, offset = 0): Bundle => | ||
transactions.map( | ||
(transaction, i) => | ||
i >= offset && i < offset + fragments.length | ||
? { | ||
...transaction, | ||
signatureMessageFragment: padTrytes(27 * 81)(fragments[i - offset] || ''), | ||
} | ||
: transaction | ||
) | ||
/** | ||
* Finalizes a bundle by calculating the bundle hash. | ||
* | ||
* @method finalizeBundle | ||
* | ||
* @param {Transaction[]} transactions - List of transactions in the bundle | ||
* | ||
* @return {Transaction[]} List of transactions in the finalized bundle | ||
*/ | ||
export const finalizeBundle = (transactions: Bundle): Bundle => { | ||
let validBundle: boolean = false | ||
const valueTrits = transactions.map(tx => trits(tx.value)).map(padTrits(81)) | ||
const timestampTrits = transactions.map(tx => trits(tx.timestamp)).map(padTrits(27)) | ||
const currentIndexTrits = transactions.map(tx => trits(tx.currentIndex)).map(padTrits(27)) | ||
const lastIndexTrits = padTrits(27)(trits(transactions[0].lastIndex)) | ||
const obsoleteTagTrits = transactions.map(tx => trits(tx.obsoleteTag)).map(padTrits(81)) | ||
const bundleHashTrits = new Int8Array(Kerl.HASH_LENGTH) | ||
while (!validBundle) { | ||
const sponge = new Kerl() | ||
for (let i = 0; i < transactions.length; i++) { | ||
const essence = trits( | ||
transactions[i].address + | ||
trytes(valueTrits[i]) + | ||
trytes(obsoleteTagTrits[i]) + | ||
trytes(timestampTrits[i]) + | ||
trytes(currentIndexTrits[i]) + | ||
trytes(lastIndexTrits) | ||
) | ||
sponge.absorb(essence, 0, essence.length) | ||
} | ||
sponge.squeeze(bundleHashTrits, 0, Kerl.HASH_LENGTH) | ||
if (normalizedBundle(bundleHashTrits).indexOf(13) !== -1) { | ||
// Insecure bundle, increment obsoleteTag and recompute bundle hash | ||
obsoleteTagTrits[0] = add(obsoleteTagTrits[0], new Int8Array(1).fill(1)) | ||
} else { | ||
validBundle = true | ||
} | ||
} | ||
return transactions.map((transaction, i) => ({ | ||
...transaction, | ||
// overwrite obsoleteTag in first entry | ||
obsoleteTag: i === 0 ? trytes(obsoleteTagTrits[0]) : transaction.obsoleteTag, | ||
bundle: trytes(bundleHashTrits), | ||
})) | ||
} |
import test from 'ava' | ||
import { addEntry, addTrytes, createBundle, finalizeBundle } from '../src/bundle' | ||
import { addEntry, addTrytes, createBundle, finalizeBundle } from '../src' | ||
@@ -4,0 +4,0 @@ const NULL_HASH = '9'.repeat(81) |
@@ -1,1 +0,65 @@ | ||
export { BundleEntry, createBundle, addEntry, addTrytes, finalizeBundle } from './bundle'; | ||
/** @module bundle */ | ||
import '../../typed-array'; | ||
import { Bundle, Hash, Transaction, // tslint:disable-line no-unused-variable | ||
Trytes } from '../../types'; | ||
export interface BundleEntry { | ||
readonly length: number; | ||
readonly address: Hash; | ||
readonly value: number; | ||
readonly tag: string; | ||
readonly timestamp: number; | ||
readonly signatureMessageFragments: ReadonlyArray<Trytes>; | ||
} | ||
export { Transaction, Bundle }; | ||
/** | ||
* Creates a bundle with given transaction entries. | ||
* | ||
* @method createBundle | ||
* | ||
* @param {BundleEntry[]} entries - Entries of single or multiple transactions with the same address | ||
* | ||
* @return {Transaction[]} List of transactions in the bundle | ||
*/ | ||
export declare const createBundle: (entries?: ReadonlyArray<Partial<BundleEntry>>) => ReadonlyArray<Transaction>; | ||
/** | ||
* Adds given transaction entry to a bundle. | ||
* | ||
* @method addEntry | ||
* | ||
* @param {Transaction[]} transactions - List of transactions currently in the bundle | ||
* | ||
* @param {object} entry - Entry of a single or multiple transactions with the same address | ||
* @param {number} [entry.length = 1] - Entry length, which indicates how many transactions in the bundle it will occupy | ||
* @param {Hash} [entry.address] - Address, defaults to all-9s | ||
* @param {number} [entry.value = 0] - Value to transfer in iotas | ||
* @param {Trytes[]} [entry.signatureMessageFragments] - List of signature message fragments, defaults to all-9s | ||
* @param {number} [entry.timestamp] - Transaction timestamp, defaults to `Math.floor(Date.now() / 1000)` | ||
* @param {string} [entry.tag] - Optional Tag, defaults to null tag (all-9s) | ||
* | ||
* @return {Transaction[]} List of transactions in the updated bundle | ||
*/ | ||
export declare const addEntry: (transactions: ReadonlyArray<Transaction>, entry: Partial<BundleEntry>) => ReadonlyArray<Transaction>; | ||
/** | ||
* Adds signature message fragments to transactions in a bundle starting at offset. | ||
* | ||
* @method addTrytes | ||
* | ||
* @param {Transaction[]} transactions - List of transactions in the bundle | ||
* | ||
* @param {Trytes[]} fragments - List of signature message fragments to add | ||
* | ||
* @param {number} [offset = 0] - Optional offset to start appending signature message fragments | ||
* | ||
* @return {Transaction[]} List of transactions in the updated bundle | ||
*/ | ||
export declare const addTrytes: (transactions: ReadonlyArray<Transaction>, fragments: ReadonlyArray<string>, offset?: number) => ReadonlyArray<Transaction>; | ||
/** | ||
* Finalizes a bundle by calculating the bundle hash. | ||
* | ||
* @method finalizeBundle | ||
* | ||
* @param {Transaction[]} transactions - List of transactions in the bundle | ||
* | ||
* @return {Transaction[]} List of transactions in the finalized bundle | ||
*/ | ||
export declare const finalizeBundle: (transactions: ReadonlyArray<Transaction>) => ReadonlyArray<Transaction>; |
@@ -1,2 +0,1 @@ | ||
/// <reference types="bluebird" /> | ||
import * as Promise from 'bluebird'; | ||
@@ -25,4 +24,4 @@ export declare type Maybe<T> = T | void; | ||
readonly value: number; | ||
readonly message: string; | ||
readonly tag: string; | ||
readonly message?: string; | ||
readonly tag?: string; | ||
readonly obsoleteTag?: string; | ||
@@ -73,3 +72,3 @@ } | ||
CHECK_CONSISTENCY = "checkConsistency", | ||
WERE_ADDRESSES_SPENT_FROM = "wereAddressesSpentFrom", | ||
WERE_ADDRESSES_SPENT_FROM = "wereAddressesSpentFrom" | ||
} | ||
@@ -105,6 +104,7 @@ export interface BaseCommand { | ||
command: IRICommand.CHECK_CONSISTENCY; | ||
readonly transactions: ReadonlyArray<Hash>; | ||
readonly tails: ReadonlyArray<Hash>; | ||
} | ||
export interface CheckConsistencyResponse { | ||
readonly state: boolean; | ||
readonly info: string; | ||
} | ||
@@ -127,2 +127,3 @@ export interface FindTransactionsQuery { | ||
readonly threshold: number; | ||
readonly tips?: ReadonlyArray<Hash>; | ||
} | ||
@@ -227,3 +228,2 @@ export interface GetBalancesResponse { | ||
} | ||
export declare type CreateProvider = (settings?: Partial<object>) => Provider; | ||
/** Attach to tangle */ | ||
@@ -230,0 +230,0 @@ export declare type AttachToTangle = (trunkTransaction: Hash, branchTransaction: Hash, minWeightMagnitude: number, trytes: ReadonlyArray<Trytes>, callback?: Callback<ReadonlyArray<Trytes>>) => Promise<ReadonlyArray<Trytes>>; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
67242
945
21