Socket
Socket
Sign inDemoInstall

@iai-skunks/ml-registry-solana

Package Overview
Dependencies
54
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.4 to 0.2.0

2

dist/bindings.js

@@ -18,3 +18,3 @@ "use strict";

////////////////////////////////////////////////////////////
const OVERHEAD_SPACE = 96;
const OVERHEAD_SPACE = 300;
////////////////////////////////////////////////////////////

@@ -21,0 +21,0 @@ /**

/// <reference types="node" />
import BN from 'bn.js';
import BN from "bn.js";
export declare class Float32 {

@@ -8,3 +8,3 @@ val: number;

* Convert to Buffer representation
*/
*/
toBuffer(): Buffer;

@@ -11,0 +11,0 @@ }

@@ -15,3 +15,3 @@ "use strict";

* Convert to Buffer representation
*/
*/
toBuffer() {

@@ -31,3 +31,3 @@ const buffer = Buffer.alloc(4);

for (const v of this.vals) {
buffers.push((new Float32(v)).toBuffer());
buffers.push(new Float32(v).toBuffer());
}

@@ -86,3 +86,3 @@ const buffer = Buffer.concat(buffers);

}
(0, assert_1.default)(b.length < 8, 'Numberu64 too large');
(0, assert_1.default)(b.length < 8, "Numberu64 too large");
const zeroPad = Buffer.alloc(8);

@@ -89,0 +89,0 @@ b.copy(zeroPad);

@@ -14,4 +14,4 @@ "use strict";

new custom_types_1.Float32(intercept).toBuffer(),
new custom_types_1.Numberu32(Buffer.from(linkFunc, 'utf8').length).toBuffer(),
Buffer.from(linkFunc, 'utf8'),
new custom_types_1.Numberu32(Buffer.from(linkFunc, "utf8").length).toBuffer(),
Buffer.from(linkFunc, "utf8"),
lamports.toBuffer(),

@@ -18,0 +18,0 @@ space.toBuffer(),

@@ -15,1 +15,21 @@ /// <reference types="node" />

}
export declare class ModelState {
coeffsStr: string;
interceptStr: string;
linkFunc: string;
seeds: string;
data: Buffer | undefined;
constructor(props: {
coeffsStr: string;
interceptStr: string;
linkFunc: string;
seeds: string;
});
get coeffs(): number[];
get intercept(): number;
static schema: Map<typeof ModelState, {
kind: string;
fields: string[][];
}>;
static retrieve(connection: Connection, modelAccountKey: PublicKey): Promise<ModelState>;
}

@@ -12,3 +12,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.ScoreState = void 0;
exports.ModelState = exports.ScoreState = void 0;
const borsh_1 = require("borsh");

@@ -23,5 +23,5 @@ // Score Data

return __awaiter(this, void 0, void 0, function* () {
const scoreAccount = yield connection.getAccountInfo(scoreAccountKey, 'processed');
const scoreAccount = yield connection.getAccountInfo(scoreAccountKey, "processed");
if (!scoreAccount) {
throw new Error('Invalid score account provided');
throw new Error("Invalid score account provided");
}

@@ -40,4 +40,44 @@ const res = (0, borsh_1.deserializeUnchecked)(this.schema, ScoreState, scoreAccount.data);

kind: "struct",
fields: [["predStr", "String"]],
},
],
]);
// Model State
class ModelState {
constructor(props) {
this.coeffsStr = props.coeffsStr;
this.interceptStr = props.interceptStr;
this.linkFunc = props.linkFunc;
this.seeds = props.seeds;
}
get coeffs() {
return this.coeffsStr.split(", ").map(Number);
}
get intercept() {
return Number(this.interceptStr);
}
static retrieve(connection, modelAccountKey) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const modelAccount = yield connection.getAccountInfo(modelAccountKey, "processed");
if (!modelAccount) {
throw new Error("Invalid score account provided");
}
const res = (0, borsh_1.deserializeUnchecked)(this.schema, ModelState, modelAccount.data);
res.data = (_a = modelAccount.data) === null || _a === void 0 ? void 0 : _a.slice();
return res;
});
}
}
exports.ModelState = ModelState;
ModelState.schema = new Map([
[
ModelState,
{
kind: "struct",
fields: [
["predStr", "String"],
["coeffsStr", "String"],
["interceptStr", "String"],
["linkFuncStr", "String"],
["seedsStr", "String"],
],

@@ -44,0 +84,0 @@ },

@@ -16,3 +16,3 @@ "use strict";

return __awaiter(this, void 0, void 0, function* () {
const buffer = (0, crypto_1.createHash)('sha256').update(name, 'utf8').digest();
const buffer = (0, crypto_1.createHash)("sha256").update(name, "utf8").digest();
return buffer;

@@ -19,0 +19,0 @@ });

{
"name": "@iai-skunks/ml-registry-solana",
"version": "0.1.4",
"version": "0.2.0",
"description": "SPL ML Model Registry/Inference JavaScript API",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

# Machine Learning Model Registry Service JavaScript bindings
![npm](https://img.shields.io/npm/v/ml-registry-solana)
![NPM](https://img.shields.io/npm/l/ml-registry-solana)
![npm](https://img.shields.io/npm/l/@iai-skunks/ml-registry-solana)
![NPM](https://img.shields.io/npm/l/@iai-skunks/ml-registry-solana)

@@ -5,0 +5,0 @@ JavaScript bindings for interacting with an spl program for registering and

@@ -38,3 +38,3 @@ import {

intercept?: number,
lamports?: number,
lamports?: number
): Promise<[TransactionInstruction, PublicKey]> {

@@ -45,5 +45,11 @@ const hashedName = await getHashedName(modelName);

? lamports
: await connection.getMinimumBalanceForRentExemption(space + OVERHEAD_SPACE);
: await connection.getMinimumBalanceForRentExemption(
space + OVERHEAD_SPACE
);
console.log("Requesting space for the model:", space + OVERHEAD_SPACE, "bytes");
console.log(
"Requesting space for the model:",
space + OVERHEAD_SPACE,
"bytes"
);
console.log("Rent for Creating Model:", balance / LAMPORTS_PER_SOL, "SOL");

@@ -54,3 +60,3 @@

[hashedName],
programId,
programId
);

@@ -73,3 +79,3 @@

new Numberu64(balance),
new Numberu32(space),
new Numberu32(space)
);

@@ -100,11 +106,16 @@

space: number,
lamports?: number,
lamports?: number
): Promise<[TransactionInstruction, PublicKey]> {
const balance = lamports
? lamports
: await connection.getMinimumBalanceForRentExemption(space + OVERHEAD_SPACE);
: await connection.getMinimumBalanceForRentExemption(
space + OVERHEAD_SPACE
);
console.log("Requesting space for the model:", space + OVERHEAD_SPACE, "bytes");
console.log("Rent for Predict Model:", balance / LAMPORTS_PER_SOL, "SOL");
console.log(
"Requesting space for the model:",
space + OVERHEAD_SPACE,
"bytes"
);
console.log("Rent for Predict Model:", balance / LAMPORTS_PER_SOL, "SOL");

@@ -115,3 +126,3 @@ const modelHashedName = await getHashedName(modelName);

[modelHashedName],
programId,
programId
);

@@ -123,3 +134,3 @@

[scoreHashedName],
programId,
programId
);

@@ -137,6 +148,6 @@

new Numberu64(balance),
new Numberu32(space),
new Numberu32(space)
);
return [instruction, scoreAccountPubkey]
return [instruction, scoreAccountPubkey];
}

@@ -1,7 +0,7 @@

import assert from 'assert';
import assert from "assert";
import BN from 'bn.js';
import BN from "bn.js";
export class Float32 {
val: number;
val: number;

@@ -13,3 +13,3 @@ constructor(v: number) {

* Convert to Buffer representation
*/
*/
toBuffer(): Buffer {

@@ -29,12 +29,10 @@ const buffer = Buffer.alloc(4);

toBuffer(): Buffer{
const buffers: Buffer[] = []
toBuffer(): Buffer {
const buffers: Buffer[] = [];
for (const v of this.vals) {
buffers.push(
(new Float32(v)).toBuffer()
)
buffers.push(new Float32(v).toBuffer());
}
const buffer = Buffer.concat(buffers);
assert(buffer.length === 4 * this.vals.length)
return buffer
assert(buffer.length === 4 * this.vals.length);
return buffer;
}

@@ -81,5 +79,5 @@ }

/**
* Construct a Numberu64 from Buffer representation
*/
/**
* Construct a Numberu64 from Buffer representation
*/
export class Numberu64 extends BN {

@@ -95,3 +93,3 @@ /**

}
assert(b.length < 8, 'Numberu64 too large');
assert(b.length < 8, "Numberu64 too large");

@@ -102,2 +100,2 @@ const zeroPad = Buffer.alloc(8);

}
}
}

@@ -15,3 +15,3 @@ import { PublicKey, TransactionInstruction } from "@solana/web3.js";

lamports: Numberu64,
space: Numberu32,
space: Numberu32
): TransactionInstruction {

@@ -25,4 +25,4 @@ const buffers = [

new Float32(intercept).toBuffer(),
new Numberu32(Buffer.from(linkFunc, 'utf8').length).toBuffer(),
Buffer.from(linkFunc, 'utf8'),
new Numberu32(Buffer.from(linkFunc, "utf8").length).toBuffer(),
Buffer.from(linkFunc, "utf8"),
lamports.toBuffer(),

@@ -69,3 +69,3 @@ space.toBuffer(),

lamports: Numberu64,
space: Numberu32,
space: Numberu32
): TransactionInstruction {

@@ -114,2 +114,2 @@ const buffers = [

});
}
}

@@ -9,6 +9,3 @@ import { Connection, PublicKey } from "@solana/web3.js";

constructor(
props: {
predStr: string,
}) {
constructor(props: { predStr: string }) {
this.predStr = props.predStr;

@@ -22,5 +19,3 @@ }

kind: "struct",
fields: [
["predStr", "String"],
],
fields: [["predStr", "String"]],
},

@@ -36,6 +31,6 @@ ],

scoreAccountKey,
'processed'
"processed"
);
if (!scoreAccount) {
throw new Error('Invalid score account provided');
throw new Error("Invalid score account provided");
}

@@ -63,9 +58,8 @@

constructor(
props: {
coeffsStr: string,
interceptStr: string,
linkFunc: string,
seeds: string,
}) {
constructor(props: {
coeffsStr: string;
interceptStr: string;
linkFunc: string;
seeds: string;
}) {
this.coeffsStr = props.coeffsStr;

@@ -78,3 +72,3 @@ this.interceptStr = props.interceptStr;

public get coeffs(): number[] {
return this.coeffsStr.split(', ').map(Number);
return this.coeffsStr.split(", ").map(Number);
}

@@ -107,6 +101,6 @@

modelAccountKey,
'processed'
"processed"
);
if (!modelAccount) {
throw new Error('Invalid score account provided');
throw new Error("Invalid score account provided");
}

@@ -124,3 +118,2 @@

}
}
}

@@ -1,6 +0,6 @@

import { createHash } from 'crypto';
import { createHash } from "crypto";
export async function getHashedName(name: string): Promise<Buffer> {
const buffer = createHash('sha256').update(name, 'utf8').digest();
const buffer = createHash("sha256").update(name, "utf8").digest();
return buffer;
}

@@ -21,4 +21,5 @@ import {

// meta data size
let modelSpace = coeffs.join(' , ').toString().length + intercept.toString().length;
let predictSpace = indVars.join(' , ').toString().length;
let modelSpace =
coeffs.join(" , ").toString().length + intercept.toString().length;
let predictSpace = indVars.join(" , ").toString().length;

@@ -25,0 +26,0 @@ await createModel(coeffs, intercept, "normal", modelSpace);

@@ -14,7 +14,3 @@ import path from "path";

import { ScoreState, ModelState } from "../src/states";
import {
createKeypairFromFile,
getPayer,
getRpcUrl,
} from "./utils";
import { createKeypairFromFile, getPayer, getRpcUrl } from "./utils";

@@ -79,3 +75,3 @@ let connection: Connection;

space: number,
lamports?: number,
lamports?: number
): Promise<void> {

@@ -95,3 +91,3 @@ modelName = "basic_lr-" + Date.now().toString();

intercept,
lamports,
lamports
);

@@ -115,4 +111,4 @@ console.log(`PDA for model account id: ${modelAccountPubkey.toBase58()}`);

space: number,
lamports?: number,
): Promise<void> {
lamports?: number
): Promise<void> {
scoreAccountName = "basic_lr-pred-" + Date.now().toString();

@@ -129,4 +125,4 @@ console.log("Creating score account with name: ", scoreAccountName);

space,
lamports,
)
lamports
);
console.log(`PDA for score account id: ${scoreAccountPubkey.toBase58()}`);

@@ -133,0 +129,0 @@

@@ -1,2 +0,2 @@

// The code in this file is an adapted version of the utils.ts from
// The code in this file is an adapted version of the utils.ts from
// https://github.com/solana-labs/example-helloworld/blob/master/src/client/utils.ts

@@ -53,5 +53,5 @@ // which is licensed under the MIT License: Copyright(c) 2018 Solana Labs, Inc

): Promise<Keypair> {
const secretKeyString = await fs.readFile(filePath, {encoding: 'utf8'});
const secretKeyString = await fs.readFile(filePath, { encoding: "utf8" });
const secretKey = Uint8Array.from(JSON.parse(secretKeyString));
return Keypair.fromSecretKey(secretKey);
return Keypair.fromSecretKey(secretKey);
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc