Skip to content

Commit

Permalink
Added tx hash generation locally
Browse files Browse the repository at this point in the history
  • Loading branch information
vpanchal-supra committed Oct 23, 2024
1 parent 9d49dd2 commit e1b69d6
Show file tree
Hide file tree
Showing 30 changed files with 300 additions and 104 deletions.
6 changes: 4 additions & 2 deletions dist/browser/index.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ declare class SupraClient {
getAccountCoinBalance(account: HexString, coinType: string): Promise<bigint>;
private waitForTransactionCompletion;
private sendTx;
private signSupraTransaction;
static signSupraTransaction(senderAccount: AptosAccount, rawTxn: TxnBuilderTypes.RawTransaction): HexString;
private getRawTxDataInJson;
private getSendTxPayload;
getSendTxPayload(senderAccount: AptosAccount, rawTxn: TxnBuilderTypes.RawTransaction): Promise<SendTxPayload>;
/**
* Send `entry_function_payload` type tx using serialized raw transaction data
* @param senderAccount Sender KeyPair
Expand All @@ -251,6 +251,8 @@ declare class SupraClient {
* @returns Serialized raw transaction object
*/
static createSerializedRawTxObject(senderAddr: HexString, senderSequenceNumber: bigint, moduleAddr: string, moduleName: string, functionName: string, functionTypeArgs: TxnBuilderTypes.TypeTag[], functionArgs: Uint8Array[], chainId: TxnBuilderTypes.ChainId, maxGas?: bigint, gasUnitPrice?: bigint, txExpiryTime?: bigint | undefined): Promise<Uint8Array>;
static createSignedTransaction(senderAccount: AptosAccount, rawTxn: TxnBuilderTypes.RawTransaction): TxnBuilderTypes.SignedTransaction;
static deriveTransactionHash(signedTransaction: TxnBuilderTypes.SignedTransaction): string;
/**
* Transfer supra coin
* @param senderAccount Sender KeyPair
Expand Down
6 changes: 4 additions & 2 deletions dist/browser/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ declare class SupraClient {
getAccountCoinBalance(account: HexString, coinType: string): Promise<bigint>;
private waitForTransactionCompletion;
private sendTx;
private signSupraTransaction;
static signSupraTransaction(senderAccount: AptosAccount, rawTxn: TxnBuilderTypes.RawTransaction): HexString;
private getRawTxDataInJson;
private getSendTxPayload;
getSendTxPayload(senderAccount: AptosAccount, rawTxn: TxnBuilderTypes.RawTransaction): Promise<SendTxPayload>;
/**
* Send `entry_function_payload` type tx using serialized raw transaction data
* @param senderAccount Sender KeyPair
Expand All @@ -251,6 +251,8 @@ declare class SupraClient {
* @returns Serialized raw transaction object
*/
static createSerializedRawTxObject(senderAddr: HexString, senderSequenceNumber: bigint, moduleAddr: string, moduleName: string, functionName: string, functionTypeArgs: TxnBuilderTypes.TypeTag[], functionArgs: Uint8Array[], chainId: TxnBuilderTypes.ChainId, maxGas?: bigint, gasUnitPrice?: bigint, txExpiryTime?: bigint | undefined): Promise<Uint8Array>;
static createSignedTransaction(senderAccount: AptosAccount, rawTxn: TxnBuilderTypes.RawTransaction): TxnBuilderTypes.SignedTransaction;
static deriveTransactionHash(signedTransaction: TxnBuilderTypes.SignedTransaction): string;
/**
* Transfer supra coin
* @param senderAccount Sender KeyPair
Expand Down
10 changes: 5 additions & 5 deletions dist/browser/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/browser/index.js.map

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions dist/browser/index.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/browser/index.mjs.map

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions dist/node/index.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ declare class SupraClient {
getAccountCoinBalance(account: HexString, coinType: string): Promise<bigint>;
private waitForTransactionCompletion;
private sendTx;
private signSupraTransaction;
static signSupraTransaction(senderAccount: AptosAccount, rawTxn: TxnBuilderTypes.RawTransaction): HexString;
private getRawTxDataInJson;
private getSendTxPayload;
getSendTxPayload(senderAccount: AptosAccount, rawTxn: TxnBuilderTypes.RawTransaction): Promise<SendTxPayload>;
/**
* Send `entry_function_payload` type tx using serialized raw transaction data
* @param senderAccount Sender KeyPair
Expand All @@ -251,6 +251,8 @@ declare class SupraClient {
* @returns Serialized raw transaction object
*/
static createSerializedRawTxObject(senderAddr: HexString, senderSequenceNumber: bigint, moduleAddr: string, moduleName: string, functionName: string, functionTypeArgs: TxnBuilderTypes.TypeTag[], functionArgs: Uint8Array[], chainId: TxnBuilderTypes.ChainId, maxGas?: bigint, gasUnitPrice?: bigint, txExpiryTime?: bigint | undefined): Promise<Uint8Array>;
static createSignedTransaction(senderAccount: AptosAccount, rawTxn: TxnBuilderTypes.RawTransaction): TxnBuilderTypes.SignedTransaction;
static deriveTransactionHash(signedTransaction: TxnBuilderTypes.SignedTransaction): string;
/**
* Transfer supra coin
* @param senderAccount Sender KeyPair
Expand Down
6 changes: 4 additions & 2 deletions dist/node/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ declare class SupraClient {
getAccountCoinBalance(account: HexString, coinType: string): Promise<bigint>;
private waitForTransactionCompletion;
private sendTx;
private signSupraTransaction;
static signSupraTransaction(senderAccount: AptosAccount, rawTxn: TxnBuilderTypes.RawTransaction): HexString;
private getRawTxDataInJson;
private getSendTxPayload;
getSendTxPayload(senderAccount: AptosAccount, rawTxn: TxnBuilderTypes.RawTransaction): Promise<SendTxPayload>;
/**
* Send `entry_function_payload` type tx using serialized raw transaction data
* @param senderAccount Sender KeyPair
Expand All @@ -251,6 +251,8 @@ declare class SupraClient {
* @returns Serialized raw transaction object
*/
static createSerializedRawTxObject(senderAddr: HexString, senderSequenceNumber: bigint, moduleAddr: string, moduleName: string, functionName: string, functionTypeArgs: TxnBuilderTypes.TypeTag[], functionArgs: Uint8Array[], chainId: TxnBuilderTypes.ChainId, maxGas?: bigint, gasUnitPrice?: bigint, txExpiryTime?: bigint | undefined): Promise<Uint8Array>;
static createSignedTransaction(senderAccount: AptosAccount, rawTxn: TxnBuilderTypes.RawTransaction): TxnBuilderTypes.SignedTransaction;
static deriveTransactionHash(signedTransaction: TxnBuilderTypes.SignedTransaction): string;
/**
* Transfer supra coin
* @param senderAccount Sender KeyPair
Expand Down
30 changes: 26 additions & 4 deletions dist/node/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/node/index.js.map

Large diffs are not rendered by default.

30 changes: 26 additions & 4 deletions dist/node/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14166,6 +14166,7 @@ var DEFAULT_WAIT_FOR_TX_COMPLETION = false;

// src/index.ts
import { sha3_256 } from "js-sha3";
import { keccak256 } from "@ethersproject/keccak256";
var SupraClient = class _SupraClient {
constructor(url2, chainId = DEFAULT_CHAIN_ID) {
this.supraNodeURL = url2;
Expand Down Expand Up @@ -14293,7 +14294,7 @@ var SupraClient = class _SupraClient {
return (await this.sendRequest(
true,
`/rpc/v1/accounts/${account.toString()}/resources`
)).data.resources;
)).data.Resources.resource;
}
/**
* Get data of resource held by given supra account
Expand Down Expand Up @@ -14707,7 +14708,7 @@ var SupraClient = class _SupraClient {
result: waitForTransactionCompletion === true ? await this.waitForTransactionCompletion(resData.data) : "Pending" /* Pending */
};
}
signSupraTransaction(senderAccount, rawTxn) {
static signSupraTransaction(senderAccount, rawTxn) {
let preHash = Uint8Array.from(
Buffer.from(sha3_256("SUPRA::RawTransaction"), "hex")
);
Expand All @@ -14719,7 +14720,7 @@ var SupraClient = class _SupraClient {
);
signatureMessage.set(preHash);
signatureMessage.set(rawTxSerializedData, preHash.length);
return senderAccount.signBuffer(signatureMessage).toString();
return senderAccount.signBuffer(signatureMessage);
}
getRawTxDataInJson(senderAccountAddress, rawTxn) {
let txPayload = rawTxn.payload.value;
Expand Down Expand Up @@ -14750,7 +14751,10 @@ var SupraClient = class _SupraClient {
authenticator: {
Ed25519: {
public_key: senderAccount.pubKey().toString(),
signature: this.signSupraTransaction(senderAccount, rawTxn)
signature: _SupraClient.signSupraTransaction(
senderAccount,
rawTxn
).toString()
}
}
}
Expand Down Expand Up @@ -14836,6 +14840,24 @@ var SupraClient = class _SupraClient {
)
);
}
static createSignedTransaction(senderAccount, rawTxn) {
return new TxnBuilderTypes.SignedTransaction(
rawTxn,
new TxnBuilderTypes.AccountAuthenticatorEd25519(
new TxnBuilderTypes.Ed25519PublicKey(
senderAccount.pubKey().toUint8Array()
),
new TxnBuilderTypes.Ed25519Signature(
_SupraClient.signSupraTransaction(senderAccount, rawTxn).toUint8Array()
)
)
);
}
static deriveTransactionHash(signedTransaction) {
let serializer = new BCS.Serializer();
signedTransaction.serialize(serializer);
return keccak256(serializer.getBytes());
}
/**
* Transfer supra coin
* @param senderAccount Sender KeyPair
Expand Down
2 changes: 1 addition & 1 deletion dist/node/index.mjs.map

Large diffs are not rendered by default.

Loading

0 comments on commit e1b69d6

Please sign in to comment.