Skip to main content

@iroha/core@0.3.1
Built and signed on GitHub Actions

Core components of Iroha JavaScript SDK.

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
2 weeks ago (0.3.1)

Core components of the Iroha JavaScript SDK.

It includes Iroha Data Model types and codecs, WebAssembly port of iroha_crypto, and utilities such as building/signing transactions/queries.

This package consists of the following modules:

  • data-model - the data model
  • crypto - cryptographic utilities
  • codec - lower-level utilities to work with the codec

Iroha Compatibility

Versions compatibility between Iroha and this package:

Iroha @iroha/core
2.0.0-rc.1.x 0.3.x, 0.2.x, 0.1.0 (broken)
2.0.0-pre-rc.20.x and before not supported, use the Legacy SDK

The Legacy SDK is the previous iteration on SDK that is no longer maintained. It is still available on Iroha Nexus NPM registry. Its source code alongside with the installation instructions could be found on the iroha-2-pre-rc branch.

Examples

Building and signing a transaction

import * as types from '@iroha/core/data-model'
import { buildTransactionPayload, signTransaction } from '@iroha/core'

const kp = types.KeyPair.random()

const account = new types.AccountId(kp.publicKey(), new types.Name('wonderland'))

const payload = buildTransactionPayload(
  types.Executable.Instructions([
    types.InstructionBox.SetKeyValue.Domain({
      object: new types.Name('wonderland'),
      key: new types.Name('foo'),
      value: types.Json.fromValue(['bar', 'baz']),
    }),
  ]),
  {
    chain: '000-000',
    authority: account,
  },
)

const signed: types.SignedTransaction = signTransaction(payload, kp.privateKey())

Parsing & encoding an asset definition id

import { getCodec } from '@iroha/core'
import * as types from '@iroha/core/data-model'
import { encodeHex } from '@std/encoding/hex'
import { assertEquals } from '@std/assert/equals'

const asset = types.AssetDefinitionId.parse("rose#wonderland")
assertEquals(asset.name.value, 'rose')
assertEquals(asset.domain.value, 'wonderland')
assertEquals(asset.toString(), 'rose#wonderland')

const encoded: Uint8Array = getCodec(types.AssetDefinitionId).encode(asset)
assertEquals(encodeHex(encoded), '28776f6e6465726c616e6410726f7365')

Parsing an account id

import { getCodec } from '@iroha/core'
import * as types from '@iroha/core/data-model'
import { encodeHex } from '@std/encoding/hex'
import { assertEquals } from '@std/assert/equals'

const raw = "ed0120B23E14F659B91736AAB980B6ADDCE4B1DB8A138AB0267E049C082A744471714E@wonderland"

const account = types.AccountId.parse(raw)
assertEquals(account.signatory.algorithm, 'ed25519')
assertEquals(account.domain.value, 'wonderland')
assertEquals(account.toString(), raw)
Built and signed on
GitHub Actions
View transparency log

Add Package

deno add jsr:@iroha/core

Import symbol

import * as core from "@iroha/core";

---- OR ----

Import directly with a jsr specifier

import * as core from "jsr:@iroha/core";

Add Package

npx jsr add @iroha/core

Import symbol

import * as core from "@iroha/core";

Add Package

yarn dlx jsr add @iroha/core

Import symbol

import * as core from "@iroha/core";

Add Package

pnpm dlx jsr add @iroha/core

Import symbol

import * as core from "@iroha/core";

Add Package

bunx jsr add @iroha/core

Import symbol

import * as core from "@iroha/core";