openledger-datanet-sdk
v0.0.1
Published
SDK for OpenLedger Datanet integration
Maintainers
Readme
OpenLedger Datanet SDK
SDK for OpenLedger Datanet integration that allows you to add data points to the blockchain and publish metadata to an API endpoint.
Installation
npm install openledger-datanet-sdkUsage
Basic Usage
import { OpenLedgerDatanetSDK } from 'openledger-datanet-sdk';
const sdk = new OpenLedgerDatanetSDK({
datanetId: 'your-datanet-uuid', // uuid
datanetAddress: 'your-datanet-address',
privateKey: 'your-private-key',
rpcUrl: 'your-rpc-url',
apiUrl: 'your-api-url',
url: 'your-openledger-url',
authToken: 'your-auth-token'
});
// Add data points
const result = await sdk.addDataPoints([
{
chaindata: {
datapointId: 1,
userAddress: '0x...',
datahash: 'your-data-hash'
},
metadata: {
description: 'Your metadata',
timestamp: Date.now()
}
}
], 'your-transaction-signature'); // signature is requiredSIWE (Sign-In with Ethereum) Authentication
// SIWE with optional API integration
const loginResult = await OpenLedgerDatanetSDK.login({
address: '0x...',
domain: 'example.com',
uri: 'https://example.com/login',
chainId: 1,
statement: 'Sign in to OpenLedger Datanet',
privateKey: 'your-private-key',
// Optional user profile data
email: '[email protected]',
name: 'John Doe',
profileImage: 'https://example.com/avatar.jpg',
referralCode: 'REF123',
oplCode: 'OPL456',
// Optional API integration
apiUrl: 'https://api.openledger-datanet.com' // Makes POST /auth/login
});
// loginResult contains:
// {
// message: "SIWE formatted message",
// public_key: "0x...",
// signature: "0x...",
// email: "[email protected]",
// name: "John Doe",
// image_url: "https://example.com/avatar.jpg",
// referral_code: "REF123",
// opl: "OPL456",
// apiResponse: { /* API response data */ }
// }
// The SDK automatically sends this data to POST /auth/login:
// {
// "message": "SIWE message...",
// "public_key": "0x...",
// "email": "[email protected]",
// "name": "John Doe",
// "image_url": "https://example.com/avatar.jpg",
// "signature": "0x...",
// "referral_code": "REF123",
// "opl": "OPL456"
// }
// Verify the signature
const verificationResult = await OpenLedgerDatanetSDK.verifyLogin(
loginResult.message,
loginResult.signature
);
if (verificationResult.isValid) {
console.log('User authenticated:', verificationResult.address);
}API
Constructor
new OpenLedgerDatanetSDK(config: OpenLedgerDatanetSDKConfig)Parameters:
datanetId(string): UUID of the datanetdatanetAddress(string): Address of the datanet contractprivateKey(string): Private key for blockchain transactionsrpcUrl(string): RPC URL for blockchain connectionapiUrl(string): API URL for metadata publishingurl(string): OpenLedgerSDK URLauthToken(string): Authentication token
Methods
addDataPoints(dataPoints, signature, gasOptions?)
Adds data points to the blockchain and publishes metadata to the API.
Parameters:
dataPoints(DataPoint[]): Array of data points to addsignature(string, required): Transaction signaturegasOptions(GasOptions, optional): Gas configuration options
Returns:
- Promise that resolves to an object containing:
blockchainResult: Result from blockchain transactionmetadataResults: Array of results from metadata API calls
OpenLedgerDatanetSDK.login(params) (Static)
Creates and signs a SIWE (Sign-In with Ethereum) message for user authentication with optional API integration.
Parameters:
params(SiweLoginParams): Configuration for SIWE messageaddress(string): User's Ethereum addressdomain(string): Domain requesting authenticationuri(string): URI of the login endpointchainId(number): Ethereum chain IDprivateKey(string): Private key to sign the messagenonce(string, optional): Custom noncestatement(string, optional): Custom statementapiUrl(string, optional): API base URL for login endpointemail(string, optional): User's emailname(string, optional): User's display nameprofileImage(string, optional): User's profile image URLreferralCode(string, optional): Referral codeoplCode(string, optional): OPL code
Returns:
- Promise that resolves to
SiweLoginResultcontaining the signed message, user data, and optional API response
API Integration:
- When
apiUrlis provided, automatically sends POST request to{apiUrl}/auth/login - Includes all user data and signature in the request body
- Handles API errors gracefully without breaking the login flow
OpenLedgerDatanetSDK.verifyLogin(message, signature) (Static)
Verifies a SIWE signature.
Parameters:
message(string): The SIWE message that was signedsignature(string): The signature from the user's wallet
Returns:
- Promise that resolves to
SiweLoginResultwith verification results
Types
DataPoint
interface DataPoint {
chaindata: {
datapointId: number;
userAddress: string;
datahash: string;
};
metadata: Record<string, any>;
}SiweLoginParams
interface SiweLoginParams {
address: string;
domain: string;
uri: string;
chainId: number;
nonce?: string;
statement?: string;
privateKey: string; // Private key to sign the message
apiUrl?: string; // API URL for login endpoint
email?: string;
name?: string;
profileImage?: string;
referralCode?: string;
oplCode?: string;
}SiweLoginResult
interface SiweLoginResult {
message: string;
public_key: string;
email: string;
name: string;
image_url: string;
signature: string;
referral_code: string;
opl: string;
isValid?: boolean;
address?: string;
apiResponse?: any; // Response from the login API
}GasOptions
interface GasOptions {
gasLimit?: bigint | string;
maxFeePerGas?: bigint | string;
maxPriorityFeePerGas?: bigint | string;
}Development
# Install dependencies
npm install
# Build the project
npm run build
# Development mode (watch)
npm run devLicense
MIT
