@arkecosystem/typescript-crypto 0.0.16 → 0.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/enums/AbiFunction.d.ts +3 -1
  2. package/dist/enums/AbiFunction.d.ts.map +1 -1
  3. package/dist/enums/AbiFunction.js +2 -0
  4. package/dist/index.js +232 -96
  5. package/dist/transactions/builders/TokenTransferBuilder.d.ts +10 -0
  6. package/dist/transactions/builders/TokenTransferBuilder.d.ts.map +1 -0
  7. package/dist/transactions/builders/TokenTransferBuilder.js +25 -0
  8. package/dist/transactions/builders/index.d.ts +1 -0
  9. package/dist/transactions/builders/index.d.ts.map +1 -1
  10. package/dist/transactions/builders/index.js +1 -0
  11. package/dist/types.d.ts +5 -0
  12. package/dist/types.d.ts.map +1 -1
  13. package/dist/utils/AbiEncoder.d.ts +2 -0
  14. package/dist/utils/AbiEncoder.d.ts.map +1 -1
  15. package/dist/utils/AbiEncoder.js +3 -0
  16. package/dist/utils/Helpers.d.ts +8 -0
  17. package/dist/utils/Helpers.d.ts.map +1 -1
  18. package/dist/utils/Helpers.js +12 -0
  19. package/dist/utils/TransactionDataEncoder.d.ts +13 -0
  20. package/dist/utils/TransactionDataEncoder.d.ts.map +1 -0
  21. package/dist/utils/TransactionDataEncoder.js +44 -0
  22. package/dist/utils/TransactionTypeIdentifier.d.ts +24 -0
  23. package/dist/utils/TransactionTypeIdentifier.d.ts.map +1 -0
  24. package/dist/utils/TransactionTypeIdentifier.js +54 -0
  25. package/dist/utils/index.d.ts +2 -0
  26. package/dist/utils/index.d.ts.map +1 -1
  27. package/dist/utils/index.js +2 -0
  28. package/package.json +1 -1
  29. package/src/enums/AbiFunction.ts +2 -0
  30. package/src/transactions/builders/TokenTransferBuilder.ts +35 -0
  31. package/src/transactions/builders/index.ts +1 -0
  32. package/src/types.ts +7 -0
  33. package/src/utils/AbiEncoder.ts +5 -0
  34. package/src/utils/Helpers.ts +15 -0
  35. package/src/utils/TransactionDataEncoder.ts +54 -0
  36. package/src/utils/TransactionTypeIdentifier.ts +65 -0
  37. package/src/utils/index.ts +2 -0
  38. package/tests/fixtures/transactions/token-transfer.json +16 -0
  39. package/tests/fixtures/transactions/transaction-data-encoder.json +15 -0
  40. package/tests/unit/transactions/builders/TokenTransferBuilder.test.ts +138 -0
  41. package/tests/unit/utils/AbiEncoder.test.ts +12 -0
  42. package/tests/unit/utils/Helpers.test.ts +10 -0
  43. package/tests/unit/utils/TransactionDataEncoder.test.ts +51 -0
  44. package/tests/unit/utils/TransactionTypeIdentifier.test.ts +199 -0
@@ -3,8 +3,10 @@ export declare enum AbiFunction {
3
3
  UNVOTE = "unvote",
4
4
  VALIDATOR_REGISTRATION = "registerValidator",
5
5
  VALIDATOR_RESIGNATION = "resignValidator",
6
+ UPDATE_VALIDATOR = "updateValidator",
6
7
  USERNAME_REGISTRATION = "registerUsername",
7
8
  USERNAME_RESIGNATION = "resignUsername",
8
- MULTIPAYMENT = "pay"
9
+ MULTIPAYMENT = "pay",
10
+ TRANSFER = "transfer"
9
11
  }
10
12
  //# sourceMappingURL=AbiFunction.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AbiFunction.d.ts","sourceRoot":"","sources":["../../src/enums/AbiFunction.ts"],"names":[],"mappings":"AAAA,oBAAY,WAAW;IACtB,IAAI,SAAS;IACb,MAAM,WAAW;IACjB,sBAAsB,sBAAsB;IAC5C,qBAAqB,oBAAoB;IACzC,qBAAqB,qBAAqB;IAC1C,oBAAoB,mBAAmB;IACvC,YAAY,QAAQ;CACpB"}
1
+ {"version":3,"file":"AbiFunction.d.ts","sourceRoot":"","sources":["../../src/enums/AbiFunction.ts"],"names":[],"mappings":"AAAA,oBAAY,WAAW;IACtB,IAAI,SAAS;IACb,MAAM,WAAW;IACjB,sBAAsB,sBAAsB;IAC5C,qBAAqB,oBAAoB;IACzC,gBAAgB,oBAAoB;IACpC,qBAAqB,qBAAqB;IAC1C,oBAAoB,mBAAmB;IACvC,YAAY,QAAQ;IACpB,QAAQ,aAAa;CACrB"}
@@ -4,7 +4,9 @@ export var AbiFunction;
4
4
  AbiFunction["UNVOTE"] = "unvote";
5
5
  AbiFunction["VALIDATOR_REGISTRATION"] = "registerValidator";
6
6
  AbiFunction["VALIDATOR_RESIGNATION"] = "resignValidator";
7
+ AbiFunction["UPDATE_VALIDATOR"] = "updateValidator";
7
8
  AbiFunction["USERNAME_REGISTRATION"] = "registerUsername";
8
9
  AbiFunction["USERNAME_RESIGNATION"] = "resignUsername";
9
10
  AbiFunction["MULTIPAYMENT"] = "pay";
11
+ AbiFunction["TRANSFER"] = "transfer";
10
12
  })(AbiFunction || (AbiFunction = {}));
package/dist/index.js CHANGED
@@ -40,9 +40,11 @@ var AbiFunction = /* @__PURE__ */ ((AbiFunction2) => {
40
40
  AbiFunction2["UNVOTE"] = "unvote";
41
41
  AbiFunction2["VALIDATOR_REGISTRATION"] = "registerValidator";
42
42
  AbiFunction2["VALIDATOR_RESIGNATION"] = "resignValidator";
43
+ AbiFunction2["UPDATE_VALIDATOR"] = "updateValidator";
43
44
  AbiFunction2["USERNAME_REGISTRATION"] = "registerUsername";
44
45
  AbiFunction2["USERNAME_RESIGNATION"] = "resignUsername";
45
46
  AbiFunction2["MULTIPAYMENT"] = "pay";
47
+ AbiFunction2["TRANSFER"] = "transfer";
46
48
  return AbiFunction2;
47
49
  })(AbiFunction || {});
48
50
 
@@ -25113,6 +25115,18 @@ var Helpers = class {
25113
25115
  static removeLeadingHexZero(hex) {
25114
25116
  return hex.replace(/^0x/, "");
25115
25117
  }
25118
+ /**
25119
+ * Adds the leading '0x' to a string.
25120
+ *
25121
+ * @param string the input without `0x`
25122
+ * @returns the hex output with the leading `0x`
25123
+ */
25124
+ static addLeadingHexZero(input) {
25125
+ if (input.startsWith("0x")) {
25126
+ return input;
25127
+ }
25128
+ return `0x${input}`;
25129
+ }
25116
25130
  };
25117
25131
 
25118
25132
  // src/transactions/builders/EvmCallBuilder.ts
@@ -28178,6 +28192,220 @@ var AbiEncoder = class extends AbiBase {
28178
28192
  encodeFunctionCall(functionName, parameters) {
28179
28193
  return Helpers.removeLeadingHexZero(this.interface.encodeFunctionData(functionName, parameters));
28180
28194
  }
28195
+ encodeFunctionCallHex(functionName, parameters) {
28196
+ return this.interface.encodeFunctionData(functionName, parameters);
28197
+ }
28198
+ };
28199
+
28200
+ // src/utils/Message.ts
28201
+ var Message = class _Message {
28202
+ constructor(message) {
28203
+ this.publicKey = message.publicKey;
28204
+ this.signature = message.signature;
28205
+ this.message = message.message;
28206
+ }
28207
+ static new(message) {
28208
+ return new _Message(message);
28209
+ }
28210
+ static async sign(message, passphrase) {
28211
+ const privateKey = PrivateKey.fromPassphrase(passphrase);
28212
+ const publicKey = PublicKey.fromPassphrase(passphrase).publicKey;
28213
+ const signature = new SigningKey(`0x${privateKey.privateKey}`).sign(hashMessage(message));
28214
+ return _Message.new({
28215
+ publicKey,
28216
+ signature: signature.serialized,
28217
+ message
28218
+ });
28219
+ }
28220
+ verify() {
28221
+ const message = new Uint8Array(new TextEncoder().encode(this.message));
28222
+ const address = Address.fromPublicKey(this.publicKey);
28223
+ const signerAddress = verifyMessage(message, this.signature);
28224
+ return signerAddress === address;
28225
+ }
28226
+ toString() {
28227
+ return JSON.stringify(this.toJson());
28228
+ }
28229
+ toObject() {
28230
+ return [this.publicKey, this.signature, this.message];
28231
+ }
28232
+ toJson() {
28233
+ return {
28234
+ publicKey: this.publicKey,
28235
+ signature: this.signature,
28236
+ message: this.message
28237
+ };
28238
+ }
28239
+ };
28240
+
28241
+ // src/utils/Slot.ts
28242
+ var Slot = class {
28243
+ static time() {
28244
+ return Math.floor(Date.now() / 1e3) - this.epoch();
28245
+ }
28246
+ static epoch() {
28247
+ return Math.floor(new Date(Network.get().epoch()).getTime() / 1e3);
28248
+ }
28249
+ };
28250
+
28251
+ // src/utils/UnitConverter.ts
28252
+ var WEI_MULTIPLIER = 1;
28253
+ var GWEI_MULTIPLIER = 1e9;
28254
+ var ARK_MULTIPLIER = 1e18;
28255
+ var UnitConverter = class {
28256
+ static parseUnits(value, unit = "ark") {
28257
+ switch (unit.toLowerCase()) {
28258
+ case "wei":
28259
+ return bignumber_default(value).multipliedBy(WEI_MULTIPLIER);
28260
+ case "gwei":
28261
+ return bignumber_default(value).multipliedBy(GWEI_MULTIPLIER);
28262
+ case "ark":
28263
+ return bignumber_default(value).multipliedBy(ARK_MULTIPLIER);
28264
+ default:
28265
+ throw new Error(`Unsupported unit: ${unit}. Supported units are 'wei', 'gwei', and 'ark'.`);
28266
+ }
28267
+ }
28268
+ static formatUnits(value, unit = "ark") {
28269
+ switch (unit.toLowerCase()) {
28270
+ case "wei":
28271
+ return bignumber_default(value).dividedBy(WEI_MULTIPLIER).toNumber();
28272
+ case "gwei":
28273
+ return bignumber_default(value).dividedBy(GWEI_MULTIPLIER).toNumber();
28274
+ case "ark":
28275
+ return bignumber_default(value).dividedBy(ARK_MULTIPLIER).toNumber();
28276
+ default:
28277
+ throw new Error(`Unsupported unit: ${unit}. Supported units are 'wei', 'gwei', and 'ark'.`);
28278
+ }
28279
+ }
28280
+ static weiToArk(value, suffix) {
28281
+ const convertedValue = new bignumber_default(this.formatUnits(this.parseUnits(value, "wei").toString(), "ark")).decimalPlaces(18).toFixed();
28282
+ if (suffix) {
28283
+ return convertedValue + " " + suffix;
28284
+ }
28285
+ return convertedValue;
28286
+ }
28287
+ static gweiToArk(value, suffix) {
28288
+ const convertedValue = new bignumber_default(this.formatUnits(this.parseUnits(value, "gwei").toString(), "ark")).decimalPlaces(18).toFixed();
28289
+ if (suffix) {
28290
+ return convertedValue + " " + suffix;
28291
+ }
28292
+ return convertedValue;
28293
+ }
28294
+ };
28295
+
28296
+ // src/utils/TransactionDataEncoder.ts
28297
+ var TransactionDataEncoder = class {
28298
+ static multiPayment(recipients, amounts) {
28299
+ return new AbiEncoder("multipayment" /* MULTIPAYMENT */).encodeFunctionCallHex("pay" /* MULTIPAYMENT */, [
28300
+ recipients,
28301
+ amounts
28302
+ ]);
28303
+ }
28304
+ static updateValidator(validatorPublicKey) {
28305
+ return new AbiEncoder("consensus" /* CONSENSUS */).encodeFunctionCallHex("updateValidator" /* UPDATE_VALIDATOR */, [
28306
+ Helpers.addLeadingHexZero(validatorPublicKey)
28307
+ ]);
28308
+ }
28309
+ static usernameRegistration(username) {
28310
+ return new AbiEncoder("usernames" /* USERNAMES */).encodeFunctionCallHex("registerUsername" /* USERNAME_REGISTRATION */, [
28311
+ username
28312
+ ]);
28313
+ }
28314
+ static usernameResignation() {
28315
+ return new AbiEncoder("usernames" /* USERNAMES */).encodeFunctionCallHex("resignUsername" /* USERNAME_RESIGNATION */, []);
28316
+ }
28317
+ static validatorRegistration(validatorPublicKey) {
28318
+ return new AbiEncoder("consensus" /* CONSENSUS */).encodeFunctionCallHex("registerValidator" /* VALIDATOR_REGISTRATION */, [
28319
+ Helpers.addLeadingHexZero(validatorPublicKey)
28320
+ ]);
28321
+ }
28322
+ static validatorResignation() {
28323
+ return new AbiEncoder("consensus" /* CONSENSUS */).encodeFunctionCallHex("resignValidator" /* VALIDATOR_RESIGNATION */, []);
28324
+ }
28325
+ static tokenTransfer(recipientAddress, amount) {
28326
+ return new AbiEncoder("token" /* TOKEN */).encodeFunctionCallHex("transfer" /* TRANSFER */, [
28327
+ recipientAddress,
28328
+ amount
28329
+ ]);
28330
+ }
28331
+ static vote(voteAddress) {
28332
+ return new AbiEncoder("consensus" /* CONSENSUS */).encodeFunctionCallHex("vote" /* VOTE */, [voteAddress]);
28333
+ }
28334
+ static unvote() {
28335
+ return new AbiEncoder("consensus" /* CONSENSUS */).encodeFunctionCallHex("unvote" /* UNVOTE */, []);
28336
+ }
28337
+ };
28338
+
28339
+ // src/utils/TransactionTypeIdentifier.ts
28340
+ var TransactionFunctionSigs = {
28341
+ MultiPayment: Abi_Multipayment_default.methodIdentifiers["pay(address[],uint256[])"],
28342
+ RegisterUsername: Abi_Usernames_default.methodIdentifiers["registerUsername(string)"],
28343
+ ResignUsername: Abi_Usernames_default.methodIdentifiers["resignUsername()"],
28344
+ Transfer: "",
28345
+ RegisterValidator: Abi_Consensus_default.methodIdentifiers["registerValidator(bytes)"],
28346
+ ResignValidator: Abi_Consensus_default.methodIdentifiers["resignValidator()"],
28347
+ Vote: Abi_Consensus_default.methodIdentifiers["vote(address)"],
28348
+ Unvote: Abi_Consensus_default.methodIdentifiers["unvote()"],
28349
+ UpdateValidator: Abi_Consensus_default.methodIdentifiers["updateValidator(bytes)"]
28350
+ };
28351
+ var TransactionTypeIdentifier = class {
28352
+ static isTransfer(data) {
28353
+ return data === TransactionFunctionSigs.Transfer;
28354
+ }
28355
+ static isVote(data) {
28356
+ return Helpers.removeLeadingHexZero(data).startsWith(TransactionFunctionSigs.Vote);
28357
+ }
28358
+ static isUnvote(data) {
28359
+ return Helpers.removeLeadingHexZero(data).startsWith(TransactionFunctionSigs.Unvote);
28360
+ }
28361
+ static isMultiPayment(data) {
28362
+ return Helpers.removeLeadingHexZero(data).startsWith(TransactionFunctionSigs.MultiPayment);
28363
+ }
28364
+ static isUsernameRegistration(data) {
28365
+ return Helpers.removeLeadingHexZero(data).startsWith(TransactionFunctionSigs.RegisterUsername);
28366
+ }
28367
+ static isUsernameResignation(data) {
28368
+ return Helpers.removeLeadingHexZero(data).startsWith(TransactionFunctionSigs.ResignUsername);
28369
+ }
28370
+ static isValidatorRegistration(data) {
28371
+ return Helpers.removeLeadingHexZero(data).startsWith(TransactionFunctionSigs.RegisterValidator);
28372
+ }
28373
+ static isValidatorResignation(data) {
28374
+ return Helpers.removeLeadingHexZero(data).startsWith(TransactionFunctionSigs.ResignValidator);
28375
+ }
28376
+ static isUpdateValidator(data) {
28377
+ return Helpers.removeLeadingHexZero(data).startsWith(TransactionFunctionSigs.UpdateValidator);
28378
+ }
28379
+ static isTokenTransfer(data) {
28380
+ try {
28381
+ const decodedData = new AbiDecoder("token" /* TOKEN */).decodeFunctionData(data);
28382
+ return decodedData.functionName === "transfer";
28383
+ } catch {
28384
+ }
28385
+ return false;
28386
+ }
28387
+ };
28388
+
28389
+ // src/transactions/builders/TokenTransferBuilder.ts
28390
+ var TokenTransferBuilder = class extends AbstractTransactionBuilder {
28391
+ constructor(data) {
28392
+ super(data);
28393
+ }
28394
+ static new(data) {
28395
+ return new this(data);
28396
+ }
28397
+ contractAddress(address) {
28398
+ this.transaction.data.to = address;
28399
+ return this;
28400
+ }
28401
+ recipient(address, amount) {
28402
+ const payload = new AbiEncoder("token" /* TOKEN */).encodeFunctionCall("transfer", [address, amount]);
28403
+ this.transaction.data["data"] = Helpers.removeLeadingHexZero(payload);
28404
+ return this;
28405
+ }
28406
+ getTransactionInstance(data) {
28407
+ return new EvmCall(data);
28408
+ }
28181
28409
  };
28182
28410
 
28183
28411
  // src/transactions/types/Multipayment.ts
@@ -28303,102 +28531,6 @@ var ValidatorRegistration = class extends AbstractTransaction {
28303
28531
  }
28304
28532
  };
28305
28533
 
28306
- // src/utils/Message.ts
28307
- var Message = class _Message {
28308
- constructor(message) {
28309
- this.publicKey = message.publicKey;
28310
- this.signature = message.signature;
28311
- this.message = message.message;
28312
- }
28313
- static new(message) {
28314
- return new _Message(message);
28315
- }
28316
- static async sign(message, passphrase) {
28317
- const privateKey = PrivateKey.fromPassphrase(passphrase);
28318
- const publicKey = PublicKey.fromPassphrase(passphrase).publicKey;
28319
- const signature = new SigningKey(`0x${privateKey.privateKey}`).sign(hashMessage(message));
28320
- return _Message.new({
28321
- publicKey,
28322
- signature: signature.serialized,
28323
- message
28324
- });
28325
- }
28326
- verify() {
28327
- const message = new Uint8Array(new TextEncoder().encode(this.message));
28328
- const address = Address.fromPublicKey(this.publicKey);
28329
- const signerAddress = verifyMessage(message, this.signature);
28330
- return signerAddress === address;
28331
- }
28332
- toString() {
28333
- return JSON.stringify(this.toJson());
28334
- }
28335
- toObject() {
28336
- return [this.publicKey, this.signature, this.message];
28337
- }
28338
- toJson() {
28339
- return {
28340
- publicKey: this.publicKey,
28341
- signature: this.signature,
28342
- message: this.message
28343
- };
28344
- }
28345
- };
28346
-
28347
- // src/utils/Slot.ts
28348
- var Slot = class {
28349
- static time() {
28350
- return Math.floor(Date.now() / 1e3) - this.epoch();
28351
- }
28352
- static epoch() {
28353
- return Math.floor(new Date(Network.get().epoch()).getTime() / 1e3);
28354
- }
28355
- };
28356
-
28357
- // src/utils/UnitConverter.ts
28358
- var WEI_MULTIPLIER = 1;
28359
- var GWEI_MULTIPLIER = 1e9;
28360
- var ARK_MULTIPLIER = 1e18;
28361
- var UnitConverter = class {
28362
- static parseUnits(value, unit = "ark") {
28363
- switch (unit.toLowerCase()) {
28364
- case "wei":
28365
- return bignumber_default(value).multipliedBy(WEI_MULTIPLIER);
28366
- case "gwei":
28367
- return bignumber_default(value).multipliedBy(GWEI_MULTIPLIER);
28368
- case "ark":
28369
- return bignumber_default(value).multipliedBy(ARK_MULTIPLIER);
28370
- default:
28371
- throw new Error(`Unsupported unit: ${unit}. Supported units are 'wei', 'gwei', and 'ark'.`);
28372
- }
28373
- }
28374
- static formatUnits(value, unit = "ark") {
28375
- switch (unit.toLowerCase()) {
28376
- case "wei":
28377
- return bignumber_default(value).dividedBy(WEI_MULTIPLIER).toNumber();
28378
- case "gwei":
28379
- return bignumber_default(value).dividedBy(GWEI_MULTIPLIER).toNumber();
28380
- case "ark":
28381
- return bignumber_default(value).dividedBy(ARK_MULTIPLIER).toNumber();
28382
- default:
28383
- throw new Error(`Unsupported unit: ${unit}. Supported units are 'wei', 'gwei', and 'ark'.`);
28384
- }
28385
- }
28386
- static weiToArk(value, suffix) {
28387
- const convertedValue = new bignumber_default(this.formatUnits(this.parseUnits(value, "wei").toString(), "ark")).decimalPlaces(18).toFixed();
28388
- if (suffix) {
28389
- return convertedValue + " " + suffix;
28390
- }
28391
- return convertedValue;
28392
- }
28393
- static gweiToArk(value, suffix) {
28394
- const convertedValue = new bignumber_default(this.formatUnits(this.parseUnits(value, "gwei").toString(), "ark")).decimalPlaces(18).toFixed();
28395
- if (suffix) {
28396
- return convertedValue + " " + suffix;
28397
- }
28398
- return convertedValue;
28399
- }
28400
- };
28401
-
28402
28534
  // src/transactions/builders/ValidatorRegistrationBuilder.ts
28403
28535
  var ValidatorRegistrationBuilder = class extends AbstractTransactionBuilder {
28404
28536
  constructor(data) {
@@ -28678,6 +28810,10 @@ export {
28678
28810
  Slot,
28679
28811
  Testnet,
28680
28812
  Abi_Token_default as TokenContract,
28813
+ TokenTransferBuilder,
28814
+ TransactionDataEncoder,
28815
+ TransactionFunctionSigs,
28816
+ TransactionTypeIdentifier,
28681
28817
  TransactionUtils,
28682
28818
  Transfer,
28683
28819
  TransferBuilder,
@@ -0,0 +1,10 @@
1
+ import { ITokenTransferBuilder, ITransaction } from "@/types";
2
+ import { AbstractTransactionBuilder } from "./AbstractTransactionBuilder";
3
+ export declare class TokenTransferBuilder extends AbstractTransactionBuilder<ITokenTransferBuilder> implements ITokenTransferBuilder {
4
+ constructor(data?: Record<string, unknown>);
5
+ static new(data?: Record<string, unknown>): TokenTransferBuilder;
6
+ contractAddress(address: string): TokenTransferBuilder;
7
+ recipient(address: string, amount: bigint): TokenTransferBuilder;
8
+ protected getTransactionInstance(data?: Record<string, unknown>): ITransaction;
9
+ }
10
+ //# sourceMappingURL=TokenTransferBuilder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TokenTransferBuilder.d.ts","sourceRoot":"","sources":["../../../src/transactions/builders/TokenTransferBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAmB,MAAM,SAAS,CAAC;AAE/E,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAM1E,qBAAa,oBACZ,SAAQ,0BAA0B,CAAC,qBAAqB,CACxD,YAAW,qBAAqB;gBAEb,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;WAInC,GAAG,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,oBAAoB;IAIhE,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,oBAAoB;IAKtD,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,oBAAoB;IAMvE,SAAS,CAAC,sBAAsB,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,YAAY;CAG9E"}
@@ -0,0 +1,25 @@
1
+ import { AbstractTransactionBuilder } from "./AbstractTransactionBuilder";
2
+ import { EvmCall } from "@/transactions/types/EvmCall";
3
+ import { Helpers } from "@/utils/Helpers";
4
+ import { AbiEncoder } from "@/utils";
5
+ import { ContractAbiType } from "@/enums";
6
+ export class TokenTransferBuilder extends AbstractTransactionBuilder {
7
+ constructor(data) {
8
+ super(data);
9
+ }
10
+ static new(data) {
11
+ return new this(data);
12
+ }
13
+ contractAddress(address) {
14
+ this.transaction.data.to = address;
15
+ return this;
16
+ }
17
+ recipient(address, amount) {
18
+ const payload = new AbiEncoder(ContractAbiType.TOKEN).encodeFunctionCall("transfer", [address, amount]);
19
+ this.transaction.data["data"] = Helpers.removeLeadingHexZero(payload);
20
+ return this;
21
+ }
22
+ getTransactionInstance(data) {
23
+ return new EvmCall(data);
24
+ }
25
+ }
@@ -1,5 +1,6 @@
1
1
  export * from "./AbstractTransactionBuilder";
2
2
  export * from "./EvmCallBuilder";
3
+ export * from "./TokenTransferBuilder";
3
4
  export * from "./MultipaymentBuilder";
4
5
  export * from "./TransferBuilder";
5
6
  export * from "./UnvoteBuilder";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/transactions/builders/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/transactions/builders/index.ts"],"names":[],"mappings":"AAAA,cAAc,8BAA8B,CAAC;AAC7C,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,eAAe,CAAC"}
@@ -1,5 +1,6 @@
1
1
  export * from "./AbstractTransactionBuilder";
2
2
  export * from "./EvmCallBuilder";
3
+ export * from "./TokenTransferBuilder";
3
4
  export * from "./MultipaymentBuilder";
4
5
  export * from "./TransferBuilder";
5
6
  export * from "./UnvoteBuilder";
package/dist/types.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import BigNumber from "bignumber.js";
2
2
  import { Result } from "ethers";
3
+ export type Hex = `0x${string}`;
3
4
  export interface TransactionData {
4
5
  gasPrice?: string | null;
5
6
  gasLimit?: string | null;
@@ -66,6 +67,10 @@ export interface IUsernameRegistrationBuilder extends ITransactionBuilder<IUsern
66
67
  export interface IEvmCallBuilder extends ITransactionBuilder<IEvmCallBuilder> {
67
68
  payload(payload: string): IEvmCallBuilder;
68
69
  }
70
+ export interface ITokenTransferBuilder extends ITransactionBuilder<ITokenTransferBuilder> {
71
+ recipient(address: string, amount: bigint): ITokenTransferBuilder;
72
+ contractAddress(address: string): ITokenTransferBuilder;
73
+ }
69
74
  export interface IMultipaymentBuilder extends ITransactionBuilder<IMultipaymentBuilder> {
70
75
  pay(address: string, amount: string | BigNumber): IMultipaymentBuilder;
71
76
  }
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","s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AC;CAC1C;AAED,MAAM,WAAW,qBAAsB,SAAQ,mBAAmB,CAAC,qBAAqB,CAAC;IACxF,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,qBAAqB,CAAC;IAClE,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,qBAAqB,CAAC;CACxD;AAED,MAAM,WAAW,oBAAqB,SAAQ,mBAAmB,CAAC,oBAAoB,CAAC;IACtF,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,oBAAoB,CAAC;CACvE;AAED,MAAM,WAAW,wBAAyB,SAAQ,mBAAmB,CAAC,wBAAwB,CAAC;CAAG"}
@@ -1,5 +1,7 @@
1
+ import { Hex } from "@/types";
1
2
  import { AbiBase } from "./AbiBase";
2
3
  export declare class AbiEncoder extends AbiBase {
3
4
  encodeFunctionCall(functionName: string, parameters: unknown[]): string;
5
+ encodeFunctionCallHex(functionName: string, parameters: unknown[]): Hex;
4
6
  }
5
7
  //# sourceMappingURL=AbiEncoder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AbiEncoder.d.ts","sourceRoot":"","sources":["../../src/utils/AbiEncoder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,qBAAa,UAAW,SAAQ,OAAO;IACtC,kBAAkB,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,MAAM;CAGvE"}
1
+ {"version":3,"file":"AbiEncoder.d.ts","sourceRoot":"","sources":["../../src/utils/AbiEncoder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,qBAAa,UAAW,SAAQ,OAAO;IACtC,kBAAkB,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,MAAM;IAIvE,qBAAqB,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,GAAG;CAGvE"}
@@ -4,4 +4,7 @@ export class AbiEncoder extends AbiBase {
4
4
  encodeFunctionCall(functionName, parameters) {
5
5
  return Helpers.removeLeadingHexZero(this.interface.encodeFunctionData(functionName, parameters));
6
6
  }
7
+ encodeFunctionCallHex(functionName, parameters) {
8
+ return this.interface.encodeFunctionData(functionName, parameters);
9
+ }
7
10
  }
@@ -1,3 +1,4 @@
1
+ import { Hex } from "@/types";
1
2
  export declare class Helpers {
2
3
  /**
3
4
  * Validates a username based on specific rules.
@@ -15,5 +16,12 @@ export declare class Helpers {
15
16
  * @returns The hex string without the leading '0x'
16
17
  */
17
18
  static removeLeadingHexZero(hex: string): string;
19
+ /**
20
+ * Adds the leading '0x' to a string.
21
+ *
22
+ * @param string the input without `0x`
23
+ * @returns the hex output with the leading `0x`
24
+ */
25
+ static addLeadingHexZero(input: string): Hex;
18
26
  }
19
27
  //# sourceMappingURL=Helpers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Helpers.d.ts","sourceRoot":"","sources":["../../src/utils/Helpers.ts"],"names":[],"mappings":"AAEA,qBAAa,OAAO;IACnB;;;;;;;OAOG;WACW,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAyBxD;;;;;OAKG;WACW,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;CAGvD"}
1
+ {"version":3,"file":"Helpers.d.ts","sourceRoot":"","sources":["../../src/utils/Helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAE9B,qBAAa,OAAO;IACnB;;;;;;;OAOG;WACW,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAyBxD;;;;;OAKG;WACW,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAIvD;;;;;OAKG;WACW,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG;CAOnD"}
@@ -35,4 +35,16 @@ export class Helpers {
35
35
  static removeLeadingHexZero(hex) {
36
36
  return hex.replace(/^0x/, ""); // Using replace to only remove the prefix, not leading zeros
37
37
  }
38
+ /**
39
+ * Adds the leading '0x' to a string.
40
+ *
41
+ * @param string the input without `0x`
42
+ * @returns the hex output with the leading `0x`
43
+ */
44
+ static addLeadingHexZero(input) {
45
+ if (input.startsWith("0x")) {
46
+ return input;
47
+ }
48
+ return `0x${input}`;
49
+ }
38
50
  }
@@ -0,0 +1,13 @@
1
+ import { Hex } from "@/types";
2
+ export declare class TransactionDataEncoder {
3
+ static multiPayment(recipients: string[], amounts: string[]): Hex;
4
+ static updateValidator(validatorPublicKey: string): Hex;
5
+ static usernameRegistration(username: string): Hex;
6
+ static usernameResignation(): Hex;
7
+ static validatorRegistration(validatorPublicKey: string): Hex;
8
+ static validatorResignation(): Hex;
9
+ static tokenTransfer(recipientAddress: string, amount: string): Hex;
10
+ static vote(voteAddress: string): Hex;
11
+ static unvote(): Hex;
12
+ }
13
+ //# sourceMappingURL=TransactionDataEncoder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TransactionDataEncoder.d.ts","sourceRoot":"","sources":["../../src/utils/TransactionDataEncoder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAG9B,qBAAa,sBAAsB;WACpB,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,GAAG;WAO1D,eAAe,CAAC,kBAAkB,EAAE,MAAM,GAAG,GAAG;WAMhD,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG;WAM3C,mBAAmB,IAAI,GAAG;WAI1B,qBAAqB,CAAC,kBAAkB,EAAE,MAAM,GAAG,GAAG;WAMtD,oBAAoB,IAAI,GAAG;WAI3B,aAAa,CAAC,gBAAgB,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,GAAG;WAO5D,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,GAAG;WAI9B,MAAM,IAAI,GAAG;CAG3B"}
@@ -0,0 +1,44 @@
1
+ import { AbiFunction, ContractAbiType } from "@/enums";
2
+ import { AbiEncoder } from "./AbiEncoder";
3
+ import { Helpers } from "./Helpers";
4
+ export class TransactionDataEncoder {
5
+ static multiPayment(recipients, amounts) {
6
+ return new AbiEncoder(ContractAbiType.MULTIPAYMENT).encodeFunctionCallHex(AbiFunction.MULTIPAYMENT, [
7
+ recipients,
8
+ amounts,
9
+ ]);
10
+ }
11
+ static updateValidator(validatorPublicKey) {
12
+ return new AbiEncoder(ContractAbiType.CONSENSUS).encodeFunctionCallHex(AbiFunction.UPDATE_VALIDATOR, [
13
+ Helpers.addLeadingHexZero(validatorPublicKey),
14
+ ]);
15
+ }
16
+ static usernameRegistration(username) {
17
+ return new AbiEncoder(ContractAbiType.USERNAMES).encodeFunctionCallHex(AbiFunction.USERNAME_REGISTRATION, [
18
+ username,
19
+ ]);
20
+ }
21
+ static usernameResignation() {
22
+ return new AbiEncoder(ContractAbiType.USERNAMES).encodeFunctionCallHex(AbiFunction.USERNAME_RESIGNATION, []);
23
+ }
24
+ static validatorRegistration(validatorPublicKey) {
25
+ return new AbiEncoder(ContractAbiType.CONSENSUS).encodeFunctionCallHex(AbiFunction.VALIDATOR_REGISTRATION, [
26
+ Helpers.addLeadingHexZero(validatorPublicKey),
27
+ ]);
28
+ }
29
+ static validatorResignation() {
30
+ return new AbiEncoder(ContractAbiType.CONSENSUS).encodeFunctionCallHex(AbiFunction.VALIDATOR_RESIGNATION, []);
31
+ }
32
+ static tokenTransfer(recipientAddress, amount) {
33
+ return new AbiEncoder(ContractAbiType.TOKEN).encodeFunctionCallHex(AbiFunction.TRANSFER, [
34
+ recipientAddress,
35
+ amount,
36
+ ]);
37
+ }
38
+ static vote(voteAddress) {
39
+ return new AbiEncoder(ContractAbiType.CONSENSUS).encodeFunctionCallHex(AbiFunction.VOTE, [voteAddress]);
40
+ }
41
+ static unvote() {
42
+ return new AbiEncoder(ContractAbiType.CONSENSUS).encodeFunctionCallHex(AbiFunction.UNVOTE, []);
43
+ }
44
+ }
@@ -0,0 +1,24 @@
1
+ export declare const TransactionFunctionSigs: {
2
+ MultiPayment: string;
3
+ RegisterUsername: string;
4
+ ResignUsername: string;
5
+ Transfer: string;
6
+ RegisterValidator: string;
7
+ ResignValidator: string;
8
+ Vote: string;
9
+ Unvote: string;
10
+ UpdateValidator: string;
11
+ };
12
+ export declare class TransactionTypeIdentifier {
13
+ static isTransfer(data: string): boolean;
14
+ static isVote(data: string): boolean;
15
+ static isUnvote(data: string): boolean;
16
+ static isMultiPayment(data: string): boolean;
17
+ static isUsernameRegistration(data: string): boolean;
18
+ static isUsernameResignation(data: string): boolean;
19
+ static isValidatorRegistration(data: string): boolean;
20
+ static isValidatorResignation(data: string): boolean;
21
+ static isUpdateValidator(data: string): boolean;
22
+ static isTokenTransfer(data: string): boolean;
23
+ }
24
+ //# sourceMappingURL=TransactionTypeIdentifier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TransactionTypeIdentifier.d.ts","sourceRoot":"","sources":["../../src/utils/TransactionTypeIdentifier.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,uBAAuB;;;;;;;;;;CAUnC,CAAC;AAEF,qBAAa,yBAAyB;WACvB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;WAIjC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;WAI7B,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;WAI/B,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;WAIrC,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;WAI7C,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;WAI5C,uBAAuB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;WAI9C,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;WAI7C,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;WAIxC,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;CAUpD"}