-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
378 additions
and
254 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"niljs": patch | ||
--- | ||
|
||
Added methods to serialize transactions and transactions with signatures |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"niljs": patch | ||
--- | ||
|
||
Added ssz serialization schemas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"niljs": patch | ||
--- | ||
|
||
Added index files inside feature directories to make root index with package exports clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,6 @@ | ||
// import { PublicClient } from "./PublicClient.js"; | ||
import { endpoint } from "../../test/mocks/endpoint.js"; | ||
import { PublicClient } from "./PublicClient.js"; | ||
|
||
// const client = new PublicClient({ | ||
// endpoint: "http://127.0.0.1:8529", | ||
// }); | ||
|
||
// test("Get block by number", async () => { | ||
// const block = await client.getBlockByNumber(1); | ||
|
||
// expect(block).toBeDefined(); | ||
// }); | ||
|
||
// i'm not sure for now how to test it. | ||
// there are at least 3 options: | ||
// 1. use mock local node | ||
// 2. use real public node | ||
// 3. use some snapshots, but updating them every time will hurt. Anyway worth to try. | ||
const client = new PublicClient({ | ||
endpoint, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from "./WalletClient.js"; | ||
export * from "./PublicClient.js"; | ||
export * from "./types/ClientConfigs.js"; | ||
export * from "./types/ISendTransactionOptions.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { bytesToHex as bytesToHexNoble } from "@noble/curves/abstract/utils"; | ||
|
||
/** | ||
* Converts bytes to a hex string. | ||
* @param bytes - The bytes to convert to a hex string. | ||
* @returns The hex string representation of the input. | ||
*/ | ||
const bytesToHex = (bytes: Uint8Array): string => { | ||
return bytesToHexNoble(bytes); | ||
}; | ||
|
||
/** | ||
* Converts bytes to a string. | ||
* @param bytes - The bytes to convert to a string. | ||
* @returns The string representation of the input. | ||
*/ | ||
const bytesToString = (bytes: Uint8Array): string => { | ||
return Buffer.from(bytes).toString("utf-8"); | ||
}; | ||
|
||
/** | ||
* Converts bytes to a number. | ||
* @param bytes - The bytes to convert to a number. | ||
* @returns The number representation of the input. | ||
*/ | ||
const bytesToNumber = (bytes: Uint8Array): number => { | ||
return Number.parseInt(bytes.toString()); | ||
}; | ||
|
||
export { bytesToHex, bytesToString, bytesToNumber }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,45 @@ | ||
import { hexToBytes } from "@noble/curves/abstract/utils"; | ||
import { | ||
type Hex, | ||
hexToBytes as hexToBytesNoble, | ||
} from "@noble/curves/abstract/utils"; | ||
|
||
/** | ||
* Convert a hex string to bytes. | ||
* @param hex - The hex string to convert to bytes. | ||
* @returns The bytes representation of the input. | ||
*/ | ||
const fromHexToBytes = (hex: string): Uint8Array => { | ||
return hexToBytes(hex); | ||
const hexToBytes = (hex: Hex): Uint8Array => { | ||
if (typeof hex !== "string") { | ||
return hexToBytes(hex.toString()); | ||
} | ||
|
||
return hexToBytesNoble(hex); | ||
}; | ||
|
||
/** | ||
* Convert a hex string to a number. | ||
* @param hex - The hex string to convert to a number. | ||
* @returns The number representation of the input. | ||
*/ | ||
const hexToNumber = (hex: Hex): number => { | ||
if (typeof hex !== "string") { | ||
return hexToNumber(hex.toString()); | ||
} | ||
|
||
return Number.parseInt(hex, 16); | ||
}; | ||
|
||
/** | ||
* Convert a hex string to a string. | ||
* @param hex - The hex string to convert to a string. | ||
* @returns The string representation of the input. | ||
*/ | ||
const hexToString = (hex: Hex): string => { | ||
if (typeof hex !== "string") { | ||
return hexToString(hex.toString()); | ||
} | ||
|
||
return Buffer.from(hex, "hex").toString("utf-8"); | ||
}; | ||
|
||
export { fromHexToBytes }; | ||
export { hexToBytes, hexToNumber, hexToString }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export * from "./fromHex.js"; | ||
export * from "./toHex.js"; | ||
export * from "./fromSsz.js"; | ||
export * from "./toSsz.js"; | ||
export * from "./fromBytes.js"; | ||
export * from "./toBytes.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { | ||
ByteVectorType, | ||
ContainerType, | ||
OptionalType, | ||
UintBigintType, | ||
UintNumberType, | ||
} from "@chainsafe/ssz"; | ||
|
||
const Bytes32 = new ByteVectorType(32); | ||
const Bytes96 = new ByteVectorType(96); | ||
const Uint32 = new UintNumberType(4); | ||
const UintBn64 = new UintBigintType(8); | ||
|
||
/** | ||
* SSZ schema for a transaction object. It includes all the fields of a transaction object. | ||
*/ | ||
const SszTransactionSchema = new ContainerType({ | ||
index: Uint32, | ||
shardId: Uint32, | ||
from: Bytes32, | ||
to: Bytes32, | ||
value: UintBn64, | ||
data: Bytes96, | ||
seqno: Uint32, | ||
signature: new OptionalType(Bytes96), | ||
maxPriorityFeePerGas: UintBn64, | ||
gasPrice: UintBn64, | ||
maxFeePerGas: UintBn64, | ||
chainId: Uint32, | ||
}); | ||
|
||
/** | ||
* SSZ schema for a signature object. It includes all the fields of a signature object. | ||
*/ | ||
const SszSignatureSchema = new ContainerType({ | ||
r: Bytes32, | ||
s: Bytes32, | ||
v: new OptionalType(UintBn64), | ||
yParity: UintBn64, | ||
}); | ||
|
||
/** | ||
* SSZ schema for a signed transaction object. It includes all the fields of a signed transaction object. | ||
*/ | ||
const SszSignedTransactionSchema = new ContainerType({ | ||
...SszTransactionSchema.fields, | ||
...SszSignatureSchema.fields, | ||
}); | ||
|
||
export { SszTransactionSchema, SszSignedTransactionSchema }; |
Empty file.
Oops, something went wrong.