@attocash/commons-core
v6.7.1-patch.1
Published
Core Atto primitives, serialization, hashing, signing, keys, addresses, blocks, and transactions.
Downloads
671
Maintainers
Readme
commons-core
Core primitives and utilities used across the Atto ecosystem. Multiplatform (JVM/JS/Wasm).
What you get:
- Mnemonic and seed derivation (BIP‑39 style)
- Keys and addresses
- Blocks and transactions (send/receive/open)
- Serialization (buffer/JSON/Protobuf) and validation helpers
- Hashing and proof‑of‑work interfaces
Installation
Gradle:
implementation("cash.atto:commons-core:<version>")NPM:
npm install @attocash/commons-coreExamples (from tests)
Generate mnemonic, derive seed, and keys
val mnemonic = AttoMnemonic.generate()
val seed = mnemonic.toSeed() // suspend
val privateKey = seed.toPrivateKey(0U)
val publicKey = privateKey.toPublicKey()
val address = AttoAddress(AttoAlgorithm.V1, publicKey)Build and validate a transaction
val receiveBlock = AttoReceiveBlock(
version = 0U.toAttoVersion(),
network = AttoNetwork.LOCAL,
algorithm = AttoAlgorithm.V1,
publicKey = publicKey,
height = 2U.toAttoHeight(),
balance = AttoAmount.MAX,
timestamp = AttoInstant.now(),
previous = AttoHash(Random.nextBytes(ByteArray(32))),
sendHashAlgorithm = AttoAlgorithm.V1,
sendHash = AttoHash(Random.Default.nextBytes(ByteArray(32))),
)
val tx = AttoTransaction(
block = receiveBlock,
signature = privateKey.sign(receiveBlock.hash),
work = AttoWorker.cpu().work(receiveBlock),
)
check(tx.isValid())Serialize/deserialize
val buf = tx.toBuffer()
val txFromBuf = AttoTransaction.fromBuffer(buf)
val json = Json.encodeToString(tx)
val txFromJson = Json.decodeFromString<AttoTransaction>(json)CPU proof‑of‑work
This example also requires commons-worker or @attocash/commons-worker.
val work = AttoWorker.cpu().work(receiveBlock)See commons-core/src/commonTest/kotlin/cash/atto/commons/AttoTransactionTest.kt for more end‑to‑end examples.
