@burstjs/core
Advanced tools
Comparing version 0.1.0-rc.3 to 0.1.0-rc.3.1
# Change Log | ||
All notable changes to this project will be documented in this file. | ||
##Unreleased | ||
- Export of Api Interface Types | ||
- Entirely removed BigNumber | ||
## 0.1.0-rc.3 | ||
@@ -5,0 +10,0 @@ ### General |
@@ -15,2 +15,3 @@ "use strict"; | ||
const sendTextMessage_1 = require("./factories/message/sendTextMessage"); | ||
const sendEncryptedTextMessage_1 = require("./factories/message/sendEncryptedTextMessage"); | ||
const getAccountTransactions_1 = require("./factories/account/getAccountTransactions"); | ||
@@ -25,3 +26,5 @@ const getUnconfirmedAccountTransactions_1 = require("./factories/account/getUnconfirmedAccountTransactions"); | ||
const sendMoney_1 = require("./factories/transaction/sendMoney"); | ||
const sendMoneyMultiOut_1 = require("./factories/transaction/sendMoneyMultiOut"); | ||
const getAliases_1 = require("./factories/account/getAliases"); | ||
const setAlias_1 = require("./factories/account/setAlias"); | ||
const getTime_1 = require("./factories/network/getTime"); | ||
@@ -60,5 +63,7 @@ const getAccount_1 = require("./factories/account/getAccount"); | ||
sendMoney: sendMoney_1.sendMoney, | ||
sendMoneyMultiOut: sendMoneyMultiOut_1.sendMoneyMultiOut, | ||
}) | ||
.withMessageApi({ | ||
sendTextMessage: sendTextMessage_1.sendTextMessage | ||
sendTextMessage: sendTextMessage_1.sendTextMessage, | ||
sendEncryptedTextMessage: sendEncryptedTextMessage_1.sendEncryptedTextMessage, | ||
}) | ||
@@ -72,2 +77,3 @@ .withAccountApi({ | ||
getAliases: getAliases_1.getAliases, | ||
setAlias: setAlias_1.setAlias, | ||
getAccount: getAccount_1.getAccount, | ||
@@ -74,0 +80,0 @@ setAccountInfo: setAccountInfo_1.setAccountInfo, |
import { BurstService } from '../../../burstService'; | ||
import { TransactionList } from '../../../typings/transactionList'; | ||
export declare const getAccountTransactions: (service: BurstService) => (accountId: string, firstIndex?: number, lastIndex?: number, numberOfConfirmations?: number, type?: number, subtype?: number) => Promise<TransactionList>; | ||
export declare const getAccountTransactions: (service: BurstService) => (accountId: string, firstIndex?: number, lastIndex?: number, numberOfConfirmations?: number, type?: number, subtype?: number, includeIndirect?: boolean) => Promise<TransactionList>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getAccountTransactions = (service) => (accountId, firstIndex, lastIndex, numberOfConfirmations, type, subtype) => service.query('getAccountTransactions', { | ||
exports.getAccountTransactions = (service) => (accountId, firstIndex, lastIndex, numberOfConfirmations, type, subtype, includeIndirect) => service.query('getAccountTransactions', { | ||
account: accountId, | ||
@@ -9,4 +9,5 @@ firstIndex, | ||
type, | ||
subtype | ||
subtype, | ||
includeIndirect | ||
}); | ||
//# sourceMappingURL=getAccountTransactions.js.map |
import { BurstService } from '../../../burstService'; | ||
import { TransactionId } from '../../../typings/transactionId'; | ||
export declare const sendTextMessage: (service: BurstService) => (message: string, recipientId: string, senderPublicKey: string, senderPrivateKey: string, fee?: number) => Promise<TransactionId>; | ||
export declare const sendTextMessage: (service: BurstService) => (message: string, recipientId: string, senderPublicKey: string, senderPrivateKey: string, deadline?: number, fee?: number) => Promise<TransactionId>; |
@@ -16,3 +16,3 @@ "use strict"; | ||
const broadcastTransaction_1 = require("../transaction/broadcastTransaction"); | ||
exports.sendTextMessage = (service) => (message, recipientId, senderPublicKey, senderPrivateKey, fee = 0.1) => __awaiter(this, void 0, void 0, function* () { | ||
exports.sendTextMessage = (service) => (message, recipientId, senderPublicKey, senderPrivateKey, deadline = 1440, fee = 0.1) => __awaiter(this, void 0, void 0, function* () { | ||
const parameters = { | ||
@@ -19,0 +19,0 @@ recipient: recipientId, |
@@ -15,7 +15,6 @@ "use strict"; | ||
const util_1 = require("@burstjs/util"); | ||
const constructAttachment_1 = require("../../../constructAttachment"); | ||
const constructAttachment_1 = require("../../../attachment/constructAttachment"); | ||
const broadcastTransaction_1 = require("./broadcastTransaction"); | ||
exports.sendMoney = (service) => (transaction, senderPublicKey, senderPrivateKey, recipientAddress) => __awaiter(this, void 0, void 0, function* () { | ||
let parameters = { | ||
requestType: 'sendMoney', | ||
amountNQT: util_1.convertNumberToNQTString(parseFloat(transaction.amountNQT)), | ||
@@ -22,0 +21,0 @@ publicKey: senderPublicKey, |
@@ -20,3 +20,7 @@ export * from './typings/api'; | ||
export * from './typings/unconfirmedTransactionList'; | ||
export * from './typings/multioutRecipientAmount'; | ||
export * from './typings/burstTime'; | ||
export * from './api'; | ||
export * from './attachment'; | ||
export * from './transaction'; | ||
export * from './constants'; |
@@ -11,2 +11,5 @@ "use strict"; | ||
__export(require("./api")); | ||
__export(require("./attachment")); | ||
__export(require("./transaction")); | ||
__export(require("./constants")); | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const crypto_1 = require("@burstjs/crypto"); | ||
class Account { | ||
@@ -13,7 +12,8 @@ constructor(data = {}) { | ||
if (data.publicKey || data.keys !== undefined) { | ||
this.keys = new crypto_1.Keys(); | ||
this.pinHash = data.pinHash || undefined; | ||
this.keys.publicKey = data.publicKey || data.keys.publicKey || undefined; | ||
this.keys.signPrivateKey = data.keys.signPrivateKey || undefined; | ||
this.keys.agreementPrivateKey = data.keys.agreementPrivateKey || undefined; | ||
this.keys = { | ||
publicKey: data.publicKey || data.keys.publicKey, | ||
signPrivateKey: data.keys.signPrivateKey, | ||
agreementPrivateKey: data.keys.agreementPrivateKey, | ||
}; | ||
} | ||
@@ -20,0 +20,0 @@ this.name = data.name || undefined; |
@@ -8,3 +8,3 @@ import { TransactionList } from '../transactionList'; | ||
export interface AccountApi { | ||
getAccountTransactions: (accountId: string, firstIndex?: number, lastIndex?: number, numberOfConfirmations?: number, type?: number, subtype?: number) => Promise<TransactionList>; | ||
getAccountTransactions: (accountId: string, firstIndex?: number, lastIndex?: number, numberOfConfirmations?: number, type?: number, subtype?: number, includeIndirect?: boolean) => Promise<TransactionList>; | ||
getUnconfirmedAccountTransactions: (accountId: string) => Promise<UnconfirmedTransactionList>; | ||
@@ -16,3 +16,4 @@ getAccountBalance: (accountId: string) => Promise<Balance>; | ||
getAliases: (accountId: string) => Promise<AliasList>; | ||
setAlias: (aliasName: string, aliasURI: string, feeNQT: string, senderPublicKey: string, senderPrivateKey: string, deadline?: number) => Promise<TransactionId>; | ||
setAccountInfo: (name: string, description: string, feeNQT: string, senderPublicKey: string, senderPrivateKey: string, deadline?: number) => Promise<TransactionId>; | ||
} |
@@ -6,2 +6,3 @@ import { BlockApi } from './blockApi'; | ||
import { AccountApi } from './accountApi'; | ||
export { BlockApi, NetworkApi, TransactionApi, MessageApi, AccountApi, }; | ||
export declare class Api { | ||
@@ -8,0 +9,0 @@ readonly block: BlockApi; |
import { TransactionId } from '../transactionId'; | ||
import { Keys } from '@burstjs/crypto'; | ||
export interface MessageApi { | ||
sendTextMessage: (message: string, recipientId: string, senderPublicKey: string, senderPrivateKey: string, fee?: number) => Promise<TransactionId>; | ||
sendTextMessage: (message: string, recipientId: string, senderPublicKey: string, senderPrivateKey: string, deadline?: number, fee?: number) => Promise<TransactionId>; | ||
sendEncryptedTextMessage: (message: string, recipientId: string, recipientPublicKey: string, senderKeys: Keys, deadline?: number, fee?: number) => Promise<TransactionId>; | ||
} |
@@ -7,2 +7,3 @@ import { TransactionId } from '../transactionId'; | ||
sendMoney: (transaction: Transaction, senderPublicKey: string, senderPrivateKey: string, recipientAddress: string) => Promise<TransactionId | Error>; | ||
sendMoneyMultiOut: (transaction: Transaction, senderPublicKey: string, senderPrivateKey: string, recipients: string, sameAmount: boolean) => Promise<TransactionId>; | ||
} |
{ | ||
"name": "@burstjs/core", | ||
"version": "0.1.0-rc.3", | ||
"version": "0.1.0-rc.3.1", | ||
"description": "Burst-related functions and models for building Burstcoin applications.", | ||
@@ -44,5 +44,5 @@ "contributors": [ | ||
"dependencies": { | ||
"@burstjs/crypto": "^0.1.0-rc.3", | ||
"@burstjs/http": "^0.1.0-rc.3", | ||
"@burstjs/util": "^0.1.0-rc.3" | ||
"@burstjs/crypto": "^0.1.0-rc.3.1", | ||
"@burstjs/http": "^0.1.0-rc.3.1", | ||
"@burstjs/util": "^0.1.0-rc.3.1" | ||
}, | ||
@@ -54,3 +54,3 @@ "husky": { | ||
}, | ||
"gitHead": "049583d0dfbf99ba6328e2291d459e8f377c5625", | ||
"gitHead": "9b5a4e07616d783e85bcae6c21b72f50db783f48", | ||
"publishConfig": { | ||
@@ -57,0 +57,0 @@ "access": "public" |
@@ -8,2 +8,4 @@ import {convertNQTStringToNumber} from '@burstjs/util'; | ||
import {getAccountBalance} from '../../factories/account/getAccountBalance'; | ||
import {TransactionType} from '../../../constants/transactionType'; | ||
import {TransactionPaymentSubtype} from '../../../constants'; | ||
@@ -34,2 +36,23 @@ const environment = loadEnvironment(); | ||
it('should getAccountTransactions with MultiOut', async () => { | ||
const transactionList = await getAccountTransactions(service)(accountId, | ||
undefined, | ||
undefined, | ||
undefined, | ||
undefined, | ||
undefined, | ||
true | ||
); | ||
expect(transactionList).not.toBeUndefined(); | ||
const {transactions} = transactionList; | ||
expect(transactions.length).toBeGreaterThan(1); | ||
const testTransaction = transactions.filter( | ||
({type, subtype}) => type === TransactionType.Payment | ||
&& (subtype === TransactionPaymentSubtype.MultiOut | ||
|| subtype === TransactionPaymentSubtype.MultiOutSameAmount) | ||
); | ||
expect(testTransaction).toBeDefined(); | ||
}); | ||
it('should getAccountTransactions paged', async () => { | ||
@@ -36,0 +59,0 @@ const transactionList = await getAccountTransactions(service)(accountId, 0, 3); |
@@ -33,3 +33,6 @@ import * as fs from 'fs'; | ||
testRecipientId: process.env.TEST_RECIPIENT_ID, | ||
testTransactionId: process.env.TEST_TRANSACTION_ID | ||
testRecipientPassphrase: process.env.TEST_RECIPIENT_PASSPHRASE, | ||
testTransactionId: process.env.TEST_TRANSACTION_ID, | ||
testEncryptedMessageTransactionId: process.env.TEST_ENCRYPTED_MESSAGE_TRANSACTION_ID | ||
// .. add more variables here | ||
@@ -36,0 +39,0 @@ }; |
import {loadEnvironment} from './helpers/environment'; | ||
import {BurstService} from '../../../burstService'; | ||
import {generateMasterKeys, getAccountIdFromPublicKey} from '@burstjs/crypto'; | ||
import {decryptMessage, generateMasterKeys, getAccountIdFromPublicKey} from '@burstjs/crypto'; | ||
import {sendTextMessage} from '../../factories/message/sendTextMessage'; | ||
import {sendEncryptedTextMessage} from '../../factories/message/sendEncryptedTextMessage'; | ||
import {getTransaction} from '../../factories/transaction/getTransaction'; | ||
import {assertAttachmentVersion} from '../../../attachment/assertAttachmentVersion'; | ||
const environment = loadEnvironment(); | ||
jest.setTimeout(environment.timeout); | ||
describe('[E2E] Message Api', () => { | ||
const service = new BurstService(environment.testNetHost, environment.testNetApiPath); | ||
let environment; | ||
let service; | ||
let senderKeys; | ||
let recipientKeys; | ||
let recipientId; | ||
beforeAll(() => { | ||
environment = loadEnvironment(); | ||
service = new BurstService(environment.testNetHost, environment.testNetApiPath); | ||
jest.setTimeout(environment.timeout); | ||
senderKeys = generateMasterKeys(environment.testPassphrase); | ||
recipientKeys = generateMasterKeys(environment.testRecipientPassphrase); | ||
recipientId = getAccountIdFromPublicKey(recipientKeys.publicKey); | ||
}); | ||
it('should sendTextMessage', async () => { | ||
const keys = generateMasterKeys(environment.testPassphrase); | ||
const transactionId = await sendTextMessage(service)( | ||
'[E2E] sendTextMessage TEST', | ||
environment.testRecipientId, | ||
keys.publicKey, | ||
keys.signPrivateKey, | ||
recipientId, | ||
senderKeys.publicKey, | ||
senderKeys.signPrivateKey, | ||
1440, | ||
0.05 | ||
@@ -28,2 +43,33 @@ ); | ||
}); | ||
it('should sendEncryptedTextMessage', async () => { | ||
const transactionId = await sendEncryptedTextMessage(service)( | ||
'[E2E] sendEncryptedTextMessage TEST (encrypted)', | ||
recipientId, | ||
recipientKeys.publicKey, | ||
senderKeys, | ||
1440, | ||
0.05 | ||
); | ||
expect(transactionId).not.toBeUndefined(); | ||
}); | ||
it('should get a transaction from BRS with encrypted message and decrypt successfully', async () => { | ||
const transaction = await getTransaction(service)(environment.testEncryptedMessageTransactionId); | ||
expect(transaction).not.toBeUndefined(); | ||
assertAttachmentVersion(transaction, 'EncryptedMessage'); | ||
const {encryptedMessage} = transaction.attachment; | ||
const recipientsMessage = decryptMessage(encryptedMessage, transaction.senderPublicKey, recipientKeys.agreementPrivateKey); | ||
const sendersMessage = decryptMessage(encryptedMessage, recipientKeys.publicKey, senderKeys.agreementPrivateKey); | ||
expect(recipientsMessage).toEqual('[E2E] sendEncryptedTextMessage TEST (encrypted)'); | ||
expect(recipientsMessage).toEqual(sendersMessage); | ||
}); | ||
}); |
import {HttpMockBuilder, Http} from '@burstjs/http'; | ||
import {BurstService} from '../../burstService'; | ||
import {generateSignature} from '@burstjs/crypto'; | ||
import {generateSignedTransactionBytes, generateSignature, encryptMessage} from '@burstjs/crypto'; | ||
import {verifySignature} from '@burstjs/crypto'; | ||
import {generateSignedTransactionBytes} from '@burstjs/crypto'; | ||
import {constructAttachment} from '../../constructAttachment'; | ||
import {constructAttachment} from '../../attachment/constructAttachment'; | ||
import {sendTextMessage} from '../factories/message/sendTextMessage'; | ||
import {broadcastTransaction} from '../factories/transaction/broadcastTransaction'; | ||
import {sendEncryptedTextMessage} from '../factories/message/sendEncryptedTextMessage'; | ||
@@ -57,2 +57,3 @@ describe('Message Api', () => { | ||
'senderPrivateKey', | ||
1440, | ||
0.2 | ||
@@ -122,2 +123,109 @@ ); | ||
}); | ||
describe('sendEncryptedTextMessage', () => { | ||
let httpMock: Http; | ||
let service: BurstService; | ||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
// @ts-ignore | ||
broadcastTransaction = jest.fn().mockImplementation(s => (_) => Promise.resolve({ | ||
fullHash: 'fullHash', | ||
transaction: 'transaction' | ||
})); | ||
// @ts-ignore | ||
encryptMessage = jest.fn( | ||
() => | ||
({ | ||
data: 'encryptedMessage', | ||
nonce: 'nonce' | ||
}) | ||
); | ||
// @ts-ignore | ||
generateSignature = jest.fn(() => 'signature'); | ||
// @ts-ignore | ||
verifySignature = jest.fn(() => true); | ||
// @ts-ignore | ||
generateSignedTransactionBytes = jest.fn(() => 'signedTransactionBytes'); | ||
httpMock = HttpMockBuilder.create().onPostReply(200, { | ||
unsignedTransactionBytes: 'unsignedHexMessage' | ||
}).build(); | ||
service = new BurstService('baseUrl', 'relPath', httpMock); | ||
}); | ||
afterEach(() => { | ||
// @ts-ignore | ||
httpMock.reset(); | ||
}); | ||
it('should sendEncryptedTextMessage', async () => { | ||
const senderKeys = { | ||
publicKey: 'publicKey', | ||
signPrivateKey: 'signPrivateKey', | ||
agreementPrivateKey: 'agreementPrivateKey', | ||
}; | ||
const {fullHash, transaction} = await sendEncryptedTextMessage(service)( | ||
'Message Text', | ||
'recipientId', | ||
'recipientPublicKey', | ||
senderKeys, | ||
1440, | ||
0.2 | ||
); | ||
expect(fullHash).toBe('fullHash'); | ||
expect(transaction).toBe('transaction'); | ||
expect(broadcastTransaction).toBeCalledTimes(1); | ||
expect(encryptMessage).toBeCalledTimes(1); | ||
expect(generateSignature).toBeCalledTimes(1); | ||
expect(verifySignature).toBeCalledTimes(1); | ||
expect(generateSignedTransactionBytes).toBeCalledTimes(1); | ||
}); | ||
it('should throw error for sendEncryptedTextMessage, when encrypted message is too large', async () => { | ||
// @ts-ignore | ||
encryptMessage = jest.fn( | ||
() => | ||
({ | ||
data: new Array(1100).fill('a').join(''), | ||
nonce: 'nonce' | ||
}) | ||
); | ||
const senderKeys = { | ||
publicKey: 'publicKey', | ||
signPrivateKey: 'signPrivateKey', | ||
agreementPrivateKey: 'agreementPrivateKey', | ||
}; | ||
try { | ||
await sendEncryptedTextMessage(service)( | ||
'Plaintext message', | ||
'recipientId', | ||
'recipientPublicKey', | ||
senderKeys, | ||
1440, | ||
0.2 | ||
); | ||
expect(false).toBe('Expected error'); | ||
} catch (e) { | ||
expect(e.message).toContain('The encrypted message exceeds allowed limit of 1024 bytes'); | ||
} | ||
expect(encryptMessage).toBeCalledTimes(1); | ||
expect(broadcastTransaction).not.toBeCalled(); | ||
expect(generateSignature).not.toBeCalled(); | ||
expect(verifySignature).not.toBeCalled(); | ||
expect(generateSignedTransactionBytes).not.toBeCalled(); | ||
}); | ||
}); | ||
}); |
@@ -6,2 +6,3 @@ import { HttpMockBuilder, Http } from '@burstjs/http'; | ||
import { sendMoney } from '../factories/transaction/sendMoney'; | ||
import { sendMoneyMultiOut } from '../factories/transaction/sendMoneyMultiOut'; | ||
import { Transaction } from '../../typings/transaction'; | ||
@@ -74,3 +75,3 @@ import { generateSignature } from '@burstjs/crypto'; | ||
.onPostReply(200, mockBroadcastResponse, | ||
'relPath?requestType=sendMoney&requestType=sendMoney&amountNQT=100000000&publicKey=recipientId&recipient=senderPrivateKey&deadline=1440&feeNQT=100000000') | ||
'relPath?requestType=sendMoney&amountNQT=100000000&publicKey=senderPublicKey&recipient=recipientId&deadline=1440&feeNQT=100000000') | ||
.onPostReply(200, mockTransaction.transaction, | ||
@@ -91,5 +92,5 @@ 'relPath?requestType=broadcastTransaction&transactionBytes=signedTransactionBytes') | ||
mockTransaction, | ||
'recipientId', | ||
'senderPublicKey', | ||
'senderPrivateKey' | ||
'senderPrivateKey', | ||
'recipientId' | ||
); | ||
@@ -103,3 +104,114 @@ expect(status).toBe('transactionId'); | ||
}); | ||
describe('sendMoneyMultiOut', () => { | ||
let service; | ||
let mockTransaction: Transaction = { | ||
transaction: 'transactionId', | ||
requestProcessingTime: 4, | ||
feeNQT: '1', | ||
amountNQT: '1', | ||
fullHash: '808d5c32b12f4d4b963404c19523b6391ddf7a04a96ec4a495703aeead76c6ff', | ||
}; | ||
const mockBroadcastResponse = { | ||
unsignedTransactionBytes: 'unsignedHexMessage' | ||
}; | ||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
// @ts-ignore | ||
generateSignature = jest.fn(() => 'signature'); | ||
// @ts-ignore | ||
verifySignature = jest.fn(() => true); | ||
// @ts-ignore | ||
generateSignedTransactionBytes = jest.fn(() => 'signedTransactionBytes'); | ||
}); | ||
afterEach(() => { | ||
// @ts-ignore | ||
httpMock.reset(); | ||
}); | ||
it('should sendMoneyMulti', async () => { | ||
httpMock = HttpMockBuilder.create() | ||
// tslint:disable:max-line-length | ||
.onPostReply(200, mockBroadcastResponse, | ||
'relPath?requestType=sendMoneyMulti&publicKey=senderPublicKey&recipients=thisIsAStringRepresentingAMultiOutPayload&deadline=1440&feeNQT=100000000') | ||
.onPostReply(200, mockTransaction.transaction, | ||
'relPath?requestType=broadcastTransaction&transactionBytes=signedTransactionBytes') | ||
.build(); | ||
service = new BurstService('baseUrl', 'relPath', httpMock); | ||
const status = await sendMoneyMultiOut(service)( | ||
mockTransaction, | ||
'senderPublicKey', | ||
'senderPrivateKey', | ||
'thisIsAStringRepresentingAMultiOutPayload', | ||
false | ||
); | ||
expect(status).toBe('transactionId'); | ||
expect(generateSignature).toBeCalledTimes(1); | ||
expect(verifySignature).toBeCalledTimes(1); | ||
expect(generateSignedTransactionBytes).toBeCalledTimes(1); | ||
}); | ||
it('should sendMoneyMultiSame', async () => { | ||
httpMock = HttpMockBuilder.create() | ||
// tslint:disable:max-line-length | ||
.onPostReply(200, mockBroadcastResponse, | ||
'relPath?requestType=sendMoneyMultiSame&publicKey=senderPublicKey&recipients=thisIsAStringRepresentingAMultiOutSamePayload&deadline=1440&feeNQT=100000000&amountNQT=100000000') | ||
.onPostReply(200, mockTransaction.transaction, | ||
'relPath?requestType=broadcastTransaction&transactionBytes=signedTransactionBytes') | ||
.build(); | ||
service = new BurstService('baseUrl', 'relPath', httpMock); | ||
const status = await sendMoneyMultiOut(service)( | ||
mockTransaction, | ||
'senderPublicKey', | ||
'senderPrivateKey', | ||
'thisIsAStringRepresentingAMultiOutSamePayload', | ||
true | ||
); | ||
expect(status).toBe('transactionId'); | ||
expect(generateSignature).toBeCalledTimes(1); | ||
expect(verifySignature).toBeCalledTimes(1); | ||
expect(generateSignedTransactionBytes).toBeCalledTimes(1); | ||
}); | ||
it('should support deadlines', async () => { | ||
httpMock = HttpMockBuilder.create() | ||
// tslint:disable:max-line-length | ||
.onPostReply(200, mockBroadcastResponse, | ||
'relPath?requestType=sendMoneyMultiSame&publicKey=senderPublicKey&recipients=thisIsAStringRepresentingAMultiOutSamePayload&deadline=720&feeNQT=100000000&amountNQT=100000000') | ||
.onPostReply(200, mockTransaction.transaction, | ||
'relPath?requestType=broadcastTransaction&transactionBytes=signedTransactionBytes') | ||
.build(); | ||
let mockTransaction2: Transaction = { | ||
deadline: 720, // 12 hrs instead of default 24 | ||
...mockTransaction | ||
}; | ||
service = new BurstService('baseUrl', 'relPath', httpMock); | ||
const status = await sendMoneyMultiOut(service)( | ||
mockTransaction2, | ||
'senderPublicKey', | ||
'senderPrivateKey', | ||
'thisIsAStringRepresentingAMultiOutSamePayload', | ||
true | ||
); | ||
expect(status).toBe('transactionId'); | ||
expect(generateSignature).toBeCalledTimes(1); | ||
expect(verifySignature).toBeCalledTimes(1); | ||
expect(generateSignedTransactionBytes).toBeCalledTimes(1); | ||
}); | ||
}); | ||
}); |
@@ -22,2 +22,4 @@ /** @module core */ | ||
import {sendTextMessage} from './factories/message/sendTextMessage'; | ||
import {sendEncryptedTextMessage} from './factories/message/sendEncryptedTextMessage'; | ||
import {getAccountTransactions} from './factories/account/getAccountTransactions'; | ||
@@ -32,3 +34,5 @@ import {getUnconfirmedAccountTransactions} from './factories/account/getUnconfirmedAccountTransactions'; | ||
import {sendMoney} from './factories/transaction/sendMoney'; | ||
import {sendMoneyMultiOut} from './factories/transaction/sendMoneyMultiOut'; | ||
import {getAliases} from './factories/account/getAliases'; | ||
import {setAlias} from './factories/account/setAlias'; | ||
import {getTime} from './factories/network/getTime'; | ||
@@ -81,5 +85,7 @@ import {getAccount} from './factories/account/getAccount'; | ||
sendMoney, | ||
sendMoneyMultiOut, | ||
}) | ||
.withMessageApi({ | ||
sendTextMessage | ||
sendTextMessage, | ||
sendEncryptedTextMessage, | ||
}) | ||
@@ -93,2 +99,3 @@ .withAccountApi({ | ||
getAliases, | ||
setAlias, | ||
getAccount, | ||
@@ -95,0 +102,0 @@ setAccountInfo, |
@@ -9,3 +9,3 @@ /** @ignore */ | ||
import {TransactionList} from '../../../typings/transactionList'; | ||
// TODO: maybe split in several getAccountTransactions like getBlocks | ||
export const getAccountTransactions = (service: BurstService): | ||
@@ -18,3 +18,4 @@ ( | ||
type?: number, | ||
subtype?: number | ||
subtype?: number, | ||
includeIndirect?: boolean | ||
) => Promise<TransactionList> => | ||
@@ -27,3 +28,4 @@ ( | ||
type?: number, | ||
subtype?: number | ||
subtype?: number, | ||
includeIndirect?: boolean | ||
): Promise<TransactionList> => | ||
@@ -36,3 +38,4 @@ service.query('getAccountTransactions', { | ||
type, | ||
subtype | ||
subtype, | ||
includeIndirect | ||
}); |
@@ -7,13 +7,18 @@ /** @ignore */ | ||
*/ | ||
import { BurstService } from '../../../burstService'; | ||
import { TransactionId } from '../../../typings/transactionId'; | ||
import { TransactionResponse } from '../../../typings/transactionResponse'; | ||
import { generateSignature } from '@burstjs/crypto'; | ||
import { verifySignature } from '@burstjs/crypto'; | ||
import { generateSignedTransactionBytes } from '@burstjs/crypto'; | ||
import { convertNumberToNQTString } from '@burstjs/util'; | ||
import {BurstService} from '../../../burstService'; | ||
import {TransactionId} from '../../../typings/transactionId'; | ||
import {TransactionResponse} from '../../../typings/transactionResponse'; | ||
import {generateSignature} from '@burstjs/crypto'; | ||
import {verifySignature} from '@burstjs/crypto'; | ||
import {generateSignedTransactionBytes} from '@burstjs/crypto'; | ||
import {convertNumberToNQTString} from '@burstjs/util'; | ||
import {broadcastTransaction} from '../transaction/broadcastTransaction'; | ||
export const sendTextMessage = (service: BurstService): | ||
(message: string, recipientId: string, senderPublicKey: string, senderPrivateKey: string, fee?: number) => Promise<TransactionId> => | ||
(message: string, | ||
recipientId: string, | ||
senderPublicKey: string, | ||
senderPrivateKey: string, | ||
deadline?: number, | ||
fee?: number) => Promise<TransactionId> => | ||
async ( | ||
@@ -24,2 +29,3 @@ message: string, | ||
senderPrivateKey: string, | ||
deadline: number = 1440, | ||
fee: number = 0.1, | ||
@@ -26,0 +32,0 @@ ): Promise<TransactionId> => { |
@@ -15,3 +15,3 @@ /** @ignore */ | ||
import { convertNumberToNQTString, convertNQTStringToNumber } from '@burstjs/util'; | ||
import { constructAttachment } from '../../../constructAttachment'; | ||
import { constructAttachment } from '../../../attachment/constructAttachment'; | ||
import {broadcastTransaction} from './broadcastTransaction'; | ||
@@ -32,3 +32,2 @@ | ||
let parameters = { | ||
requestType: 'sendMoney', | ||
amountNQT: convertNumberToNQTString(parseFloat(transaction.amountNQT)), | ||
@@ -35,0 +34,0 @@ publicKey: senderPublicKey, |
@@ -30,2 +30,3 @@ /** @ignore */ | ||
*/ | ||
// TODO: introduce a Service Context class, substituting the parameter list by a single object | ||
constructor(baseUrl: string, relativePath: string = '', httpClient?: Http) { | ||
@@ -32,0 +33,0 @@ this._http = httpClient ? httpClient : new HttpImpl(baseUrl); |
/** @module core */ | ||
export * from './typings/api'; | ||
@@ -21,5 +22,9 @@ export * from './typings/account'; | ||
export * from './typings/unconfirmedTransactionList'; | ||
export * from './typings/multioutRecipientAmount'; | ||
export * from './typings/burstTime'; | ||
export * from './api'; | ||
export * from './attachment'; | ||
export * from './transaction'; | ||
export * from './constants'; | ||
@@ -23,3 +23,3 @@ /** @module core */ | ||
public accountRS: string; | ||
public assetBalances: AssetBalance[] | ||
public assetBalances: AssetBalance[]; | ||
public balanceNQT: string; | ||
@@ -45,7 +45,8 @@ public description: string; | ||
if (data.publicKey || data.keys !== undefined) { | ||
this.keys = new Keys(); | ||
this.pinHash = data.pinHash || undefined; | ||
this.keys.publicKey = data.publicKey || data.keys.publicKey || undefined; | ||
this.keys.signPrivateKey = data.keys.signPrivateKey || undefined; | ||
this.keys.agreementPrivateKey = data.keys.agreementPrivateKey || undefined; | ||
this.keys = { | ||
publicKey: data.publicKey || data.keys.publicKey, | ||
signPrivateKey: data.keys.signPrivateKey, | ||
agreementPrivateKey: data.keys.agreementPrivateKey, | ||
}; | ||
} | ||
@@ -52,0 +53,0 @@ this.name = data.name || undefined; |
@@ -23,2 +23,3 @@ /** @module core */ | ||
* @param {number?} subtype The subtype of transactions to fetch | ||
* @param {boolean?} includeIndirect Includes indirect transaction, i.e. multi out payments. Default is `true` | ||
* @return {Promise<TransactionList>} List of transactions | ||
@@ -32,3 +33,4 @@ */ | ||
type?: number, | ||
subtype?: number | ||
subtype?: number, | ||
includeIndirect?: boolean | ||
) => Promise<TransactionList>; | ||
@@ -104,2 +106,28 @@ | ||
/** | ||
* Registers an Alias with the Burst blockchain | ||
* | ||
* The transaction will be broadcasted in two steps. | ||
* 1. Send the setAlias call with public key to the network | ||
* 2. Take the returned unsigned message and sign it, i.e. the private key won't be transmitted. | ||
* | ||
* @param aliasName The alias name | ||
* @param aliasURI The alias URI | ||
* @param feeNQT The fee to pay | ||
* @param name The name of the account | ||
* @param senderPublicKey The senders public key for sending an _unsigned_ message | ||
* @param senderPrivateKey The senders private key to _sign_ the message | ||
* @param deadline The deadline, in minutes, for the transaction to be confirmed | ||
* @return The Transaction ID | ||
*/ | ||
setAlias: ( | ||
aliasName: string, | ||
aliasURI: string, | ||
feeNQT: string, | ||
senderPublicKey: string, | ||
senderPrivateKey: string, | ||
deadline?: number, | ||
) => Promise<TransactionId>; | ||
/** | ||
* Sets account information for an account | ||
@@ -118,3 +146,3 @@ * | ||
* @param deadline The deadline, in minutes, for the transaction to be confirmed | ||
* @return The Transaction | ||
* @return The Transaction ID | ||
*/ | ||
@@ -121,0 +149,0 @@ setAccountInfo: ( |
@@ -9,2 +9,11 @@ /** @module core */ | ||
export { | ||
BlockApi, | ||
NetworkApi, | ||
TransactionApi, | ||
MessageApi, | ||
AccountApi, | ||
}; | ||
/** | ||
@@ -11,0 +20,0 @@ * API Interface used by [[composeApi]] |
/** @module core */ | ||
import {TransactionId} from '../transactionId'; | ||
import {Keys} from '@burstjs/crypto'; | ||
@@ -21,2 +22,3 @@ /** | ||
* @param senderPrivateKey The senders private key to _sign_ the message | ||
* @param deadline The optional deadline (in minutes) for the transaction to be confirmed, 1440 minutes maximum | ||
* @param fee The optional fee (expressed in Burst) for the message, default is 0.1 Burst. | ||
@@ -30,4 +32,26 @@ * @return The Transaction Id | ||
senderPrivateKey: string, | ||
deadline?: number, | ||
fee?: number | ||
) => Promise<TransactionId>; | ||
/** | ||
* Broadcasts an _encrypted_ text message to the network/blockchain | ||
* It's analogous to sendTextMessage but encrypts the message priorly | ||
* | ||
* @param message The _text_ message to be encrypted and sent | ||
* @param recipientId The recipients Id, not RS Address | ||
* @param keys The senders key set for encryption and signing | ||
* @param deadline The optional deadline (in minutes) for the transaction to be confirmed, 1440 minutes maximum | ||
* @param fee The optional fee (expressed in Burst) for the message, default is 0.1 Burst. | ||
* @return The Transaction Id | ||
*/ | ||
sendEncryptedTextMessage: ( | ||
message: string, | ||
recipientId: string, | ||
recipientPublicKey: string, | ||
senderKeys: Keys, | ||
deadline?: number, | ||
fee?: number | ||
) => Promise<TransactionId>; | ||
} |
@@ -48,2 +48,25 @@ /** @module core */ | ||
) => Promise<TransactionId | Error>; | ||
/** | ||
* Sends a multi-out request to the blockchain | ||
* | ||
* The transaction will be broadcasted in two steps. | ||
* 1. If sameAmount is true. "sendMoneyMultiSame" is called, otherwise "sendMoneyMulti" is called | ||
* 2. Take the returned unsigned message and sign it, i.e. the private key won't be transmitted. | ||
* | ||
* @param transaction The unsigned transaction | ||
* @param senderPublicKey The senders public key for sending an _unsigned_ message | ||
* @param senderPrivateKey The senders private key to _sign_ the message | ||
* @param recipients The multi-out string of recipient->amount key value pairs | ||
* @param sameAmount Whether all recipients will receive the same amount | ||
* @return The Transaction | ||
*/ | ||
sendMoneyMultiOut: ( | ||
transaction: Transaction, | ||
senderPublicKey: string, | ||
senderPrivateKey: string, | ||
recipients: string, | ||
sameAmount: boolean | ||
) => Promise<TransactionId>; | ||
} |
@@ -14,2 +14,4 @@ /** @module core */ | ||
*/ | ||
// TODO: review attachment, as this applies only for sending messages | ||
export class Attachment { | ||
@@ -16,0 +18,0 @@ public type?: string; |
@@ -33,1 +33,2 @@ /** @module core */ | ||
} | ||
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
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
258724
333
4900
Updated@burstjs/http@^0.1.0-rc.3.1
Updated@burstjs/util@^0.1.0-rc.3.1