Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@dsnp/graph-sdk

Package Overview
Dependencies
Maintainers
2
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dsnp/graph-sdk - npm Package Compare versions

Comparing version 0.0.0-41d73d to 0.0.0-53025e

dist/js/import-bundle-builder.d.ts

22

dist/js/graph.d.ts

@@ -1,23 +0,23 @@

import { ImportBundle, Update, DsnpGraphEdge, Action, DsnpPublicKey, DsnpKeys, Config, ConnectionType, PrivacyType } from "./models";
import { ImportBundle, Update, DsnpGraphEdge, Action, DsnpPublicKey, DsnpKeys, Config, ConnectionType, PrivacyType, GraphKeyPair } from "./models";
import { EnvironmentInterface } from "./models/environment";
export declare class Graph {
private handle;
constructor(environment: EnvironmentInterface, capacity?: number);
constructor(environment: EnvironmentInterface);
getGraphHandle(): number;
getGraphConfig(environment: EnvironmentInterface): Promise<Config>;
getSchemaIdFromConfig(environment: EnvironmentInterface, connectionType: ConnectionType, privacyType: PrivacyType): Promise<number>;
getGraphCapacity(): Promise<number>;
getGraphStatesCount(): Promise<number>;
containsUserGraph(dsnpUserId: number): Promise<boolean>;
containsUserGraph(dsnpUserId: string): Promise<boolean>;
getGraphUsersCount(): Promise<number>;
removeUserGraph(dsnpUserId: number): Promise<boolean>;
removeUserGraph(dsnpUserId: string): Promise<boolean>;
importUserData(payload: ImportBundle[]): Promise<boolean>;
exportUpdates(): Promise<Update[]>;
getConnectionsForUserGraph(dsnpUserId: number, schemaId: number, includePending: boolean): Promise<DsnpGraphEdge[]>;
getConnectionsForUserGraph(dsnpUserId: string, schemaId: number, includePending: boolean): Promise<DsnpGraphEdge[]>;
applyActions(actions: Action[]): Promise<boolean>;
forceCalculateGraphs(dsnpUserId: number): Promise<Update[]>;
getConnectionsWithoutKeys(): Promise<number[]>;
getOneSidedPrivateFriendshipConnections(dsnpUserId: number): Promise<DsnpGraphEdge[]>;
getPublicKeys(dsnpUserId: number): Promise<DsnpPublicKey[]>;
deserializeDsnpKeys(keys: DsnpKeys): Promise<DsnpPublicKey[]>;
forceCalculateGraphs(dsnpUserId: string): Promise<Update[]>;
getConnectionsWithoutKeys(): Promise<string[]>;
getOneSidedPrivateFriendshipConnections(dsnpUserId: string): Promise<DsnpGraphEdge[]>;
getPublicKeys(dsnpUserId: string): Promise<DsnpPublicKey[]>;
static deserializeDsnpKeys(keys: DsnpKeys): Promise<DsnpPublicKey[]>;
static generateKeyPair(keyType: number): Promise<GraphKeyPair>;
freeGraphState(): Promise<boolean>;

@@ -24,0 +24,0 @@ printHelloGraph(): void;

@@ -6,9 +6,4 @@ "use strict";

class Graph {
constructor(environment, capacity) {
if (capacity) {
this.handle = index_1.graphsdkModule.initializeGraphStateWithCapacity(environment, capacity);
}
else {
this.handle = index_1.graphsdkModule.initializeGraphState(environment);
}
constructor(environment) {
this.handle = index_1.graphsdkModule.initializeGraphState(environment);
}

@@ -24,5 +19,2 @@ getGraphHandle() {

}
getGraphCapacity() {
return index_1.graphsdkModule.getGraphCapacity(this.handle);
}
getGraphStatesCount() {

@@ -64,5 +56,8 @@ return index_1.graphsdkModule.getGraphStatesCount();

}
deserializeDsnpKeys(keys) {
static deserializeDsnpKeys(keys) {
return index_1.graphsdkModule.deserializeDsnpKeys(keys);
}
static generateKeyPair(keyType) {
return index_1.graphsdkModule.generateKeyPair(keyType);
}
freeGraphState() {

@@ -69,0 +64,0 @@ return index_1.graphsdkModule.freeGraphState(this.handle);

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const graph_1 = require("./graph");
const models_1 = require("./models");
const config_1 = require("./models/config");

@@ -8,3 +9,2 @@ const environment_1 = require("./models/environment");

const config = {};
config.sdkMaxUsersGraphSize = 100;
config.sdkMaxStaleFriendshipDays = 100;

@@ -20,2 +20,3 @@ config.maxPageId = 100;

config.schemaMap = { 1: schemaConfig };
config.graphPublicKeySchemaId = 11;
return config;

@@ -38,3 +39,3 @@ }

expect(config).toBeDefined();
expect(config.sdkMaxUsersGraphSize).toEqual(100);
expect(config.graphPublicKeySchemaId).toEqual(11);
await graph.freeGraphState();

@@ -47,3 +48,3 @@ });

expect(config).toBeDefined();
expect(config.sdkMaxUsersGraphSize).toEqual(1000);
expect(config.graphPublicKeySchemaId).toEqual(5);
const schema_id = await graph.getSchemaIdFromConfig(environment, config_1.ConnectionType.Follow, config_1.PrivacyType.Public);

@@ -58,15 +59,4 @@ expect(schema_id).toEqual(1);

expect(config).toBeDefined();
expect(config.sdkMaxUsersGraphSize).toEqual(1000);
await graph.freeGraphState();
});
test('initialize graph with low capacity of 100 should return the same capacity', async () => {
const config = getTestConfig();
const environment = { environmentType: environment_1.EnvironmentType.Dev, config };
const graph = new graph_1.Graph(environment, 100);
const handle = graph.getGraphHandle();
expect(handle).toBeDefined();
const capacity = await graph.getGraphCapacity();
expect(capacity).toEqual(100);
await graph.freeGraphState();
});
test('getGraphStatesCount should be zero after previous graph is freed', async () => {

@@ -111,3 +101,3 @@ const config = getTestConfig();

expect(handle).toBeDefined();
const contains = await graph.containsUserGraph(1);
const contains = await graph.containsUserGraph("1");
expect(contains).toEqual(false);

@@ -122,3 +112,3 @@ await graph.freeGraphState();

expect(handle).toBeDefined();
const removed = await graph.removeUserGraph(1);
const removed = await graph.removeUserGraph("1");
expect(removed).toEqual(true);

@@ -143,3 +133,3 @@ await graph.freeGraphState();

const dsnpKeys1 = {
dsnpUserId: dsnpUserId1,
dsnpUserId: dsnpUserId1.toString(),
keysHash: 100,

@@ -149,3 +139,3 @@ keys: [],

const dsnpKeys2 = {
dsnpUserId: dsnpUserId2,
dsnpUserId: dsnpUserId2.toString(),
keysHash: 100,

@@ -155,3 +145,3 @@ keys: [],

const importBundle1 = {
dsnpUserId: dsnpUserId1,
dsnpUserId: dsnpUserId1.toString(),
schemaId: 1,

@@ -163,3 +153,3 @@ keyPairs: keyPairs1,

const importBundle2 = {
dsnpUserId: dsnpUserId2,
dsnpUserId: dsnpUserId2.toString(),
schemaId: 1,

@@ -196,9 +186,9 @@ keyPairs: keyPairs2,

type: "Connect",
ownerDsnpUserId: 1,
ownerDsnpUserId: "1",
connection: {
dsnpUserId: 2,
dsnpUserId: "2",
schemaId: 1,
},
dsnpKeys: {
dsnpUserId: 2,
dsnpUserId: "2",
keysHash: 100,

@@ -226,9 +216,9 @@ keys: [],

type: "Connect",
ownerDsnpUserId: 1,
ownerDsnpUserId: "1",
connection: {
dsnpUserId: 2,
dsnpUserId: "2",
schemaId: 1,
},
dsnpKeys: {
dsnpUserId: 2,
dsnpUserId: "2",
keysHash: 100,

@@ -241,6 +231,6 @@ keys: [],

expect(applied).toEqual(true);
const connections = await graph.getConnectionsForUserGraph(1, 1, true);
const connections = await graph.getConnectionsForUserGraph("1", 1, true);
expect(connections).toBeDefined();
expect(connections.length).toEqual(1);
const forceCalculateGraphs = await graph.forceCalculateGraphs(1);
const forceCalculateGraphs = await graph.forceCalculateGraphs("1");
expect(forceCalculateGraphs).toBeDefined();

@@ -259,3 +249,3 @@ expect(forceCalculateGraphs.length).toEqual(0);

expect(async () => {
await graph.getOneSidedPrivateFriendshipConnections(1);
await graph.getOneSidedPrivateFriendshipConnections("1");
}).rejects.toThrow('User graph for 1 is not imported');

@@ -269,5 +259,5 @@ await graph.freeGraphState();

expect(handle).toBeDefined();
const connections = await graph.getPublicKeys(1);
expect(connections).toBeDefined();
expect(connections.length).toEqual(0);
const keys = await graph.getPublicKeys("1");
expect(keys).toBeDefined();
expect(keys.length).toEqual(0);
await graph.freeGraphState();

@@ -281,9 +271,9 @@ });

const keys = {
dsnpUserId: 2,
dsnpUserId: "2",
keysHash: 100,
keys: [],
};
const connections = await graph.deserializeDsnpKeys(keys);
expect(connections).toBeDefined();
expect(connections.length).toEqual(0);
const des_keys = await graph_1.Graph.deserializeDsnpKeys(keys);
expect(des_keys).toBeDefined();
expect(des_keys.length).toEqual(0);
await graph.freeGraphState();

@@ -297,9 +287,9 @@ });

type: "Connect",
ownerDsnpUserId: 1,
ownerDsnpUserId: "1",
connection: {
dsnpUserId: 2,
dsnpUserId: "2",
schemaId: public_follow_graph_schema_id,
},
dsnpKeys: {
dsnpUserId: 2,
dsnpUserId: "2",
keysHash: 100,

@@ -313,3 +303,3 @@ keys: [],

expect(applied).toEqual(true);
let connections_including_pending = await graph.getConnectionsForUserGraph(1, public_follow_graph_schema_id, true);
let connections_including_pending = await graph.getConnectionsForUserGraph("1", public_follow_graph_schema_id, true);
expect(connections_including_pending).toBeDefined();

@@ -331,3 +321,3 @@ expect(connections_including_pending.length).toEqual(1);

type: "AddGraphKey",
ownerDsnpUserId: dsnpOwnerId,
ownerDsnpUserId: dsnpOwnerId.toString(),
newPublicKey: new Uint8Array(x25519_public_key),

@@ -351,3 +341,3 @@ };

let dsnp_keys = {
dsnpUserId: dsnp_key_owner,
dsnpUserId: dsnp_key_owner.toString(),
keysHash: 100,

@@ -362,6 +352,12 @@ keys: [

const environment = { environmentType: environment_1.EnvironmentType.Mainnet };
const graph = new graph_1.Graph(environment);
const deserialized_keys = await graph.deserializeDsnpKeys(dsnp_keys);
const deserialized_keys = await graph_1.Graph.deserializeDsnpKeys(dsnp_keys);
expect(deserialized_keys).toBeDefined();
});
test('generateKeyPair should return a key pair', async () => {
const keyPair = await graph_1.Graph.generateKeyPair(models_1.GraphKeyType.X25519);
expect(keyPair).toBeDefined();
expect(keyPair.publicKey).toBeDefined();
expect(keyPair.secretKey).toBeDefined();
expect(keyPair.keyType).toEqual(models_1.GraphKeyType.X25519);
});
//# sourceMappingURL=graph.test.js.map

@@ -1,25 +0,27 @@

import { Action, Config, ConnectionType, DsnpGraphEdge, DsnpKeys, DsnpPublicKey, EnvironmentInterface, ImportBundle, PrivacyType, Update } from "./models";
import { Action, Config, ConnectionType, DsnpGraphEdge, DsnpKeys, DsnpPublicKey, EnvironmentInterface, GraphKeyPair, GraphKeyType, ImportBundle, PrivacyType, Update } from "./models";
export interface Native {
printHelloGraph(): void;
initializeGraphState(environment: EnvironmentInterface): number;
initializeGraphStateWithCapacity(environment: EnvironmentInterface, capacity: number): number;
getGraphConfig(environment: EnvironmentInterface): Promise<Config>;
getSchemaIdFromConfig(environment: EnvironmentInterface, connectionType: ConnectionType, privacyType: PrivacyType): Promise<number>;
getGraphCapacity(handle: number): Promise<number>;
getGraphStatesCount(): Promise<number>;
getGraphUsersCount(handle: number): Promise<number>;
containsUserGraph(handle: number, dsnpUserId: number): Promise<boolean>;
removeUserGraph(handle: number, dsnpUserId: number): Promise<boolean>;
containsUserGraph(handle: number, dsnpUserId: string): Promise<boolean>;
removeUserGraph(handle: number, dsnpUserId: string): Promise<boolean>;
importUserData(handle: number, payload: ImportBundle[]): Promise<boolean>;
applyActions(handle: number, actions: Action[]): Promise<boolean>;
exportUpdates(handle: number): Promise<Update[]>;
getConnectionsForUserGraph(handle: number, dsnpUserId: number, schemaId: number, includePending: boolean): Promise<DsnpGraphEdge[]>;
forceCalculateGraphs(handle: number, dsnpUserId: number): Promise<Update[]>;
getConnectionsWithoutKeys(handle: number): Promise<number[]>;
getOneSidedPrivateFriendshipConnections(handle: number, dsnpUserId: number): Promise<DsnpGraphEdge[]>;
getPublicKeys(handle: number, dsnpUserId: number): Promise<DsnpPublicKey[]>;
getConnectionsForUserGraph(handle: number, dsnpUserId: string, schemaId: number, includePending: boolean): Promise<DsnpGraphEdge[]>;
forceCalculateGraphs(handle: number, dsnpUserId: string): Promise<Update[]>;
getConnectionsWithoutKeys(handle: number): Promise<string[]>;
getOneSidedPrivateFriendshipConnections(handle: number, dsnpUserId: string): Promise<DsnpGraphEdge[]>;
getPublicKeys(handle: number, dsnpUserId: string): Promise<DsnpPublicKey[]>;
deserializeDsnpKeys(keys: DsnpKeys): Promise<DsnpPublicKey[]>;
generateKeyPair(keyType: GraphKeyType): Promise<GraphKeyPair>;
freeGraphState(handle: number): Promise<boolean>;
}
export declare const graphsdkModule: Native;
export * from "./models";
export * from "./graph";
export * from "./import-bundle-builder";
//# sourceMappingURL=index.d.ts.map
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -19,2 +33,6 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

exports.graphsdkModule = loadNativeModule();
// Export the models
__exportStar(require("./models"), exports);
__exportStar(require("./graph"), exports);
__exportStar(require("./import-bundle-builder"), exports);
//# sourceMappingURL=index.js.map

@@ -8,3 +8,2 @@ "use strict";

const config = {};
config.sdkMaxUsersGraphSize = 100;
config.sdkMaxStaleFriendshipDays = 100;

@@ -20,2 +19,3 @@ config.maxPageId = 100;

config.schemaMap = { 1: schemaConfig };
config.graphPublicKeySchemaId = 11;
return config;

@@ -22,0 +22,0 @@ }

@@ -5,3 +5,3 @@ import { Connection } from "./connection";

type: "Connect";
ownerDsnpUserId: number;
ownerDsnpUserId: string;
connection: Connection;

@@ -12,3 +12,3 @@ dsnpKeys?: DsnpKeys;

type: "Disconnect";
ownerDsnpUserId: number;
ownerDsnpUserId: string;
connection: Connection;

@@ -18,3 +18,3 @@ }

type: "AddGraphKey";
ownerDsnpUserId: number;
ownerDsnpUserId: string;
newPublicKey: Uint8Array;

@@ -21,0 +21,0 @@ }

@@ -18,3 +18,2 @@ declare enum DsnpVersion {

interface Config {
sdkMaxUsersGraphSize: number;
sdkMaxStaleFriendshipDays: number;

@@ -27,2 +26,3 @@ maxGraphPageSizeBytes: number;

};
graphPublicKeySchemaId: number;
dsnpVersions: DsnpVersion[];

@@ -29,0 +29,0 @@ }

export interface Connection {
dsnpUserId: number;
dsnpUserId: string;
schemaId: number;
}
//# sourceMappingURL=connection.d.ts.map
export interface DsnpGraphEdge {
userId: number;
userId: string;
since: number;
}
//# sourceMappingURL=graph_edge.d.ts.map

@@ -6,3 +6,3 @@ export interface KeyData {

export interface DsnpKeys {
dsnpUserId: number;
dsnpUserId: string;
keysHash: number;

@@ -25,3 +25,3 @@ keys: KeyData[];

export interface ImportBundle {
dsnpUserId: number;
dsnpUserId: string;
schemaId: number;

@@ -28,0 +28,0 @@ keyPairs: GraphKeyPair[];

export interface DsnpPublicKey {
key: Uint8Array;
keyId?: Uint8Array;
keyId?: string;
}
//# sourceMappingURL=public_keys.d.ts.map
export interface PersistPageUpdate {
type: "PersistPage";
ownerDsnpUserId: number;
ownerDsnpUserId: string;
schemaId: number;

@@ -11,3 +11,3 @@ pageId: number;

type: "DeletePage";
ownerDsnpUserId: number;
ownerDsnpUserId: string;
schemaId: number;

@@ -19,3 +19,3 @@ pageId: number;

type: "AddKey";
ownerDsnpUserId: number;
ownerDsnpUserId: string;
prevHash: number;

@@ -22,0 +22,0 @@ payload: Uint8Array;

@@ -10,3 +10,3 @@ # DSNP Graph SDK

```bash
npm install @dsnp/graph-sdk
npm install @dsnp/graph-sdk@latest
```

@@ -105,3 +105,3 @@

#### Constructor: new Graph(environment: EnvironmentInterface, capacity?: number)
#### Constructor: new Graph(environment: EnvironmentInterface)

@@ -111,3 +111,2 @@ Creates a new instance of the Graph class.

- `environment`: An object that represents the environment details.
- `capacity` (optional): The initial capacity of the graph.

@@ -117,3 +116,2 @@ #### Methods

- `getGraphHandle(): number`: Returns the handle to the native graph state.
- `getGraphCapacity(): Promise<number>`: Retrieves the capacity of the graph.
- `getGraphSize(): Promise<number>`: Retrieves the current size of the graph.

@@ -133,3 +131,3 @@ - `containsUserGraph(dsnpUserId: number): Promise<boolean>`: Checks if the graph contains the user graph for the specified DSNP user ID.

- `getGraphConfig(environment: EnvironmentInterface): Promise<Config>`: Retrieves the graph configuration.
- `getSchemaIdFromConfig(environment: EnvironmentInterface, connectionType: ConnectionType, privacyType: PrivacyType): Promise<number>`: Retrieves the schema ID from the graph configuration.
- `getSchemaIdFromConfig(environment: EnvironmentInterface, connectionType: ConnectionType, privacyType: PrivacyType): Promise<number>`: Retrieves the schema ID from the graph configuration.
- `freeGraphState(): void`: Frees the graph state.

@@ -156,3 +154,3 @@

### Create and export a new graph
```typescript

@@ -212,3 +210,3 @@ import { Graph, EnvironmentInterface, EnvironmentType } from "@dsnp/graph-sdk";

graph.freeGraphState();
```

@@ -242,3 +240,3 @@

const deserialized_keys = await graph.deserializeDsnpKeys(dsnp_keys);
const deserialized_keys = await Graph.deserializeDsnpKeys(dsnp_keys);

@@ -348,3 +346,3 @@ graph.freeGraphState();

const applied = await graph.applyActions(actions);
```
{
"name": "@dsnp/graph-sdk",
"version": "0.0.0-41d73d",
"version": "0.0.0-53025e",
"author": "Amplica Labs",

@@ -5,0 +5,0 @@ "license": "ISC",

@@ -10,3 +10,3 @@ # DSNP Graph SDK

```bash
npm install @dsnp/graph-sdk
npm install @dsnp/graph-sdk@latest
```

@@ -105,3 +105,3 @@

#### Constructor: new Graph(environment: EnvironmentInterface, capacity?: number)
#### Constructor: new Graph(environment: EnvironmentInterface)

@@ -111,3 +111,2 @@ Creates a new instance of the Graph class.

- `environment`: An object that represents the environment details.
- `capacity` (optional): The initial capacity of the graph.

@@ -117,3 +116,2 @@ #### Methods

- `getGraphHandle(): number`: Returns the handle to the native graph state.
- `getGraphCapacity(): Promise<number>`: Retrieves the capacity of the graph.
- `getGraphSize(): Promise<number>`: Retrieves the current size of the graph.

@@ -133,3 +131,3 @@ - `containsUserGraph(dsnpUserId: number): Promise<boolean>`: Checks if the graph contains the user graph for the specified DSNP user ID.

- `getGraphConfig(environment: EnvironmentInterface): Promise<Config>`: Retrieves the graph configuration.
- `getSchemaIdFromConfig(environment: EnvironmentInterface, connectionType: ConnectionType, privacyType: PrivacyType): Promise<number>`: Retrieves the schema ID from the graph configuration.
- `getSchemaIdFromConfig(environment: EnvironmentInterface, connectionType: ConnectionType, privacyType: PrivacyType): Promise<number>`: Retrieves the schema ID from the graph configuration.
- `freeGraphState(): void`: Frees the graph state.

@@ -156,3 +154,3 @@

### Create and export a new graph
```typescript

@@ -212,3 +210,3 @@ import { Graph, EnvironmentInterface, EnvironmentType } from "@dsnp/graph-sdk";

graph.freeGraphState();
```

@@ -242,3 +240,3 @@

const deserialized_keys = await graph.deserializeDsnpKeys(dsnp_keys);
const deserialized_keys = await Graph.deserializeDsnpKeys(dsnp_keys);

@@ -348,3 +346,3 @@ graph.freeGraphState();

const applied = await graph.applyActions(actions);
```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc