SahyadriSahyadriAPI

JavaScript SDK

Official JavaScript/TypeScript SDK for Sahyadri L1 Blockchain. Post-quantum secure, pure JavaScript implementation with no WASM dependencies.

Installation

npm install @sahyadrinet/web3.js

Requirements:
• Node.js >= 18.0.0
• Modern browser (Chrome, Firefox, Safari, Edge)
• TypeScript >= 5.0 (optional)

Generate Keypair

import { keypair } from '@sahyadrinet/web3.js';

const { publicKey, secretKey } = keypair();

console.log('Public Key:', publicKey.length, 'bytes');   // 1952
console.log('Secret Key:', secretKey.length, 'bytes');   // 4032

Output: Public Key: 1952 bytes, Secret Key: 4032 bytes

Sign & Verify

import { keypair, sign, verify } from '@sahyadrinet/web3.js';

const { publicKey, secretKey } = keypair();
const message = new TextEncoder().encode('Hello Sahyadri!');
const signature = sign(secretKey, message);

console.log('Signature:', signature.length, 'bytes');    // 3309
console.log('Valid:', verify(publicKey, signature, message)); // true

Tamper Detection

SDK automatically detects if a message was changed after signing. This is how blockchain transaction integrity works.

import { keypair, sign, verify } from '@sahyadrinet/web3.js';

const { publicKey, secretKey } = keypair();
const originalMsg = new TextEncoder().encode('Send 100 KANA');
const signature = sign(secretKey, originalMsg);

// Original message verifies correctly
console.log(verify(publicKey, signature, originalMsg));       // true

// Tampered message FAILS verification
const tamperedMsg = new TextEncoder().encode('Send 1000 KANA');
console.log(verify(publicKey, signature, tamperedMsg));       // false

Output:
true
false

Address Generation

import { keypair, pubkeyToAddress } from '@sahyadrinet/web3.js';

const { publicKey } = keypair();
const address = pubkeyToAddress(publicKey);
console.log(address); // csm1sxh5at56p0c6s9gwtj0mumwcly258gexk5zxp0xvj6

DID (Decentralized Identifier)

import { keypair, generateDidIdentifier } from '@sahyadrinet/web3.js';

const { publicKey } = keypair();
const did = `did:sahyadri:${generateDidIdentifier(publicKey)}`;

console.log(did);
// did:sahyadri:FWSFYxictWRNYQNeyFvy4ciH2LDKqgkR

CREST Model (Identity Standard)

import {
  keypair, pubkeyToAddress, generateDidIdentifier,
  CrestBuilder, createDidCommService
} from '@sahyadrinet/web3.js';

const { publicKey } = keypair();
const address = pubkeyToAddress(publicKey);
const did = `did:sahyadri:${generateDidIdentifier(publicKey)}`;
const pkHex = Buffer.from(publicKey).toString('hex');

const doc = CrestBuilder.new(did, address, pkHex)
  .addAuthentication({
    id: '#auth-key-1',
    type: 'MLDSA65VerificationKey2025',
    publicKeyHex: pkHex
  })
  .addService(createDidCommService('https://node.sahyadri.network/didcomm'))
  .setVersion(1)
  .build();

Wallet Integration

import { Wallet } from '@sahyadrinet/web3.js';

const wallet = new Wallet('ws://127.0.0.1:27110');
await wallet.connect();
wallet.create();

const balance = await wallet.getBalance();
const txId = await wallet.send('csm1srecipient...', 100000);

Browser Usage (CDN)

<script type="module">
  import { keypair } from 'https://esm.sh/@sahyadrinet/web3.js';
  const { publicKey } = keypair();
  console.log('Keys generated in browser!');
</script>

No build step needed! Works directly in modern browsers.

API Reference

FunctionDescriptionReturns
keypair()Generate ML-DSA-65 keypair{ publicKey, secretKey }
sign(sk, msg)Sign messageUint8Array (3309B)
verify(pk, sig, msg)Verify signatureboolean
pubkeyToAddress(pk)Derive addressstring (csm1s...)
generateDidIdentifier(pk)DID identifierstring (32 chars)
isValidDidFormat(did)Validate DIDboolean
parseDid(did)Parse DID{ method, identifier }

Security Parameters

ParameterValueExplanation
N256Polynomial degree
Q8380417Prime modulus
K6Matrix rows
L5Matrix columns
Security Level192-bitAES strength

Changelog

v0.1.1 (Current)

  • Added DID/CREST identity layer
  • Added address generation (csm1s...)
  • Added CREST document builder
  • Added DID operation signing/verification

v0.1.0

  • Initial release
  • ML-DSA-65 (Dilithium3) keypair generation
  • Post-quantum signing & verification
  • Pure JavaScript (no WASM)