Skip to content

Commit

Permalink
Release v0.10.4 (#163)
Browse files Browse the repository at this point in the history
* add deadline create from uint64

* update package

* remove log

* remove sample code

* add ignore sample

* fix signed number from txn payload

* add featrue to sign txn payload directly

* Fix receipts (#162)

* update receipt type, hide mosaic levy receipt

* fix test case for mosaic rental fee receipt type

* add missing liquidity provider class export

* update package
  • Loading branch information
sleepyOwl14 authored Nov 16, 2023
1 parent d4ee6e7 commit 814b8c3
Show file tree
Hide file tree
Showing 20 changed files with 408 additions and 438 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,6 @@ modules.xml
# End of https://www.gitignore.io/api/intellij+iml
dist/
ts-docs
docs/
docs/

sample
410 changes: 201 additions & 209 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tsjs-xpx-chain-sdk",
"version": "0.10.3",
"version": "0.10.4",
"description": "Proximax Blockchain sdk for typescript and javascript",
"scripts": {
"pretest": "npm run build",
Expand Down Expand Up @@ -31,7 +31,7 @@
"devDependencies": {
"@types/chai": "^4.3.0",
"@types/crypto-js": "^3.1.43",
"@types/lodash": "^4.14.136",
"@types/lodash": "^4.14.201",
"@types/mocha": "^5.2.7",
"@types/node": "^12.6.8",
"@types/utf8": "^2.1.6",
Expand All @@ -47,16 +47,16 @@
"ts-mockito": "^2.4.2",
"ts-node": "^8.3.0",
"tslint": "^5.18.0",
"typescript": "~4.2.0",
"typescript": "5.2.2",
"typescript-require": "^0.2.10"
},
"dependencies": {
"@js-joda/core": "^4.0.0",
"@noble/hashes": "^1.3.0",
"axios": "^0.21.4",
"axios": "^1.6.2",
"bip39": "^3.0.3",
"bluebird": "^3.5.5",
"crypto-js": "^3.1.9-1",
"crypto-js": "^4.2",
"flatbuffers": "^23.3.3",
"js-sha3": "^0.8.0",
"ripemd160": "^2.0.2",
Expand Down
140 changes: 0 additions & 140 deletions sample/testAggregate.ts

This file was deleted.

17 changes: 0 additions & 17 deletions sample/testConfig.ts

This file was deleted.

26 changes: 26 additions & 0 deletions src/infrastructure/builders/VerifiableTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,32 @@ export class VerifiableTransaction {
};
}

/**
* @param {KeyPair } keyPair KeyPair instance
* @param {string} generationHash Network generation hash hex
* @param {DerivationScheme} dScheme The derivation scheme
* @returns {module:model/TransactionPayload} - Signed Transaction Payload
*/
static signTransactionPayload(txnPayload: string, keyPair, generationHash, dScheme: DerivationScheme = DerivationScheme.Ed25519Sha3) {
const generationHashBytes = Array.from(convert.hexToUint8(generationHash));
const byteBuffer = Array.from(convert.hexToUint8(txnPayload));
const signingBytes = new Uint8Array(generationHashBytes.concat(byteBuffer.slice(4 + 64 + 32)));
const keyPairEncoded = KeyPair.createKeyPairFromPrivateKeyString(keyPair.privateKey, dScheme);
const signature = Array.from(KeyPair.sign(keyPair, new Uint8Array(signingBytes), dScheme));
const signedTransactionBuffer = byteBuffer
.splice(0, 4)
.concat(signature)
.concat(Array.from(keyPairEncoded.publicKey))
.concat(byteBuffer
.splice(64 + 32, byteBuffer.length));
const uint8Data = Uint8Array.from(signedTransactionBuffer);
const payload = convert.uint8ArrayToHex(uint8Data);
return {
payload,
hash: VerifiableTransaction.createTransactionHash(payload, generationHashBytes),
};
}

serialize() {
return this.schema.serialize(Array.from(this.bytes));
}
Expand Down
2 changes: 1 addition & 1 deletion src/infrastructure/receipt/CreateReceiptFromDTO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const CreateReceiptFromDTO = (receiptDTO, networkType): Receipt => {
case ReceiptType.LockSecret_Completed:
case ReceiptType.LockSecret_Expired:
return createBalanceChangeReceipt(receiptDTO, networkType);
case ReceiptType.Mosaic_Levy:
// case ReceiptType.Mosaic_Levy:
case ReceiptType.Mosaic_Rental_Fee:
case ReceiptType.Namespace_Rental_Fee:
return createBalanceTransferReceipt(receiptDTO, networkType);
Expand Down
4 changes: 0 additions & 4 deletions src/infrastructure/schemas/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ export class Attribute {
// tslint:disable-next-line:max-classes-per-file
export class ScalarAttribute extends Attribute {
typeSize: any;
name: any;
/**
* @constructor
* @param {string} name schema attribute name
Expand All @@ -281,7 +280,6 @@ export class ScalarAttribute extends Attribute {
// tslint:disable-next-line:max-classes-per-file
export class ArrayAttribute extends Attribute {
typeSize: any;
name: any;
/**
* @constructor
* @param name - {string}
Expand All @@ -307,7 +305,6 @@ export class ArrayAttribute extends Attribute {
// tslint:disable-next-line:max-classes-per-file
export class TableAttribute extends Attribute {
schema: any;
name: any;
/**
*
* @param {string} name
Expand Down Expand Up @@ -340,7 +337,6 @@ export class TableAttribute extends Attribute {
// tslint:disable-next-line:max-classes-per-file
export class TableArrayAttribute extends Attribute {
schema: any;
name: any;
/**
* @constructor
* @param {string} name
Expand Down
31 changes: 28 additions & 3 deletions src/infrastructure/transaction/CreateTransactionFromPayload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,8 @@ const CreateTransaction = (type: number, transactionData: string, txnVersion: Tr

case TransactionType.MODIFY_MULTISIG_ACCOUNT:
// read bytes
const minRemovalDelta = extractNumberFromHexReverse(transactionData.substring(0, 2));
const minApprovalDelta = extractNumberFromHexReverse(transactionData.substring(2, 4));
const minRemovalDelta = extractSignedNumberFromHexReverse(transactionData.substring(0, 2));
const minApprovalDelta = extractSignedNumberFromHexReverse(transactionData.substring(2, 4));
const modificationsCount = extractNumberFromHexReverse(transactionData.substring(4, 6));

const multiSigModificationSubString = transactionData.substring(6);
Expand Down Expand Up @@ -679,7 +679,7 @@ const CreateTransaction = (type: number, transactionData: string, txnVersion: Tr
* @returns {number}
*/
const extractValueSizeDelta = (hexValue: string): number => {
return convert.hexToInt(convert.hexReverse(hexValue))
return extractSignedNumberFromHexReverse(hexValue);
};

/**
Expand All @@ -691,6 +691,31 @@ const extractNumberFromHexReverse = (hexValue: string): number => {
return parseInt(convert.uint8ArrayToHex(convert.hexToUint8(hexValue).reverse()), 16);
};

/**
* @internal
* @param hexValue - Hex representation of the number
* @returns {number} - Signed number
*/
const extractSignedNumberFromHexReverse = (hexValue: string): number => {

const bytesLength = hexValue.length / 2;
const unsignedNumber = parseInt(convert.uint8ArrayToHex(convert.hexToUint8(hexValue).reverse()), 16);
const binaryString = unsignedNumber.toString(2);

// compare bits
if((bytesLength * 8) > binaryString.length){
return unsignedNumber;
}
else if(binaryString.substring(0, 1) === "0"){
return unsignedNumber;
}

const maxValue = parseInt("FF".repeat(bytesLength), 16);
const negativeNumber = ~(maxValue - unsignedNumber);

return negativeNumber;
};

/**
* @internal
* @param hexValue - Hex representation of the number
Expand Down
10 changes: 10 additions & 0 deletions src/model/account/Account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,16 @@ export class Account {
return transaction.preV2SignWith(this, generationHash);
}

/**
* Sign a transaction payload, please make sure the transaction version scheme is correct
* @param transaction - The transaction payload to be signed.
* @param generationHash - Network generation hash hex
* @return {SignedTransaction}
*/
public signTransactionPayload(payload: string, generationHash: string): SignedTransaction {
return Transaction.signPayload(payload, this, generationHash);
}

/**
* Sign transaction with cosignatories creating a new SignedTransaction
* @param transaction - The aggregate transaction to be signed.
Expand Down
5 changes: 5 additions & 0 deletions src/model/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export * from './receipt/InflationReceipt';
export * from './receipt/Receipt';
export * from './receipt/ReceiptSource';
export * from './receipt/ReceiptType';
export * from './receipt/ReceiptGroupType';
export * from './receipt/ReceiptVersion';
export * from './receipt/ResolutionEntry';
export * from './receipt/ResolutionStatement';
Expand Down Expand Up @@ -224,6 +225,10 @@ export * from './transaction/storage/NewStoragePaymentTransaction';
export * from './transaction/storage/NewVerificationPaymentTransaction';
export * from './transaction/storage/ReplicatorOffboardingTransaction';

// Liquidity Provider
export * from './liquidity/LiquidityProvider';
export * from './liquidity/LiquidityProviderSearch';

// Storage
export * from './storage/DriveInfo';
export * from './storage/DriveInfoSearch';
Expand Down
Loading

0 comments on commit 814b8c3

Please sign in to comment.