New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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-b34245 to 0.0.0-bfb138

dist/js/dsnp_graph_sdk_node.node

71

dist/js/graph.test.js

@@ -274,2 +274,73 @@ "use strict";

});
test('Create and export a new graph', async () => {
let mainnet_environment = { environmentType: environment_1.EnvironmentType.Mainnet };
let graph = new graph_1.Graph(mainnet_environment);
let public_follow_graph_schema_id = await graph.getSchemaIdFromConfig(mainnet_environment, config_1.ConnectionType.Follow, config_1.PrivacyType.Public);
let connect_action = {
type: "Connect",
ownerDsnpUserId: 1,
connection: {
dsnpUserId: 2,
schemaId: public_follow_graph_schema_id,
},
dsnpKeys: {
dsnpUserId: 2,
keysHash: 100,
keys: [],
},
};
let actions = [];
actions.push(connect_action);
let applied = await graph.applyActions(actions);
expect(applied).toEqual(true);
let connections_including_pending = await graph.getConnectionsForUserGraph(1, public_follow_graph_schema_id, true);
expect(connections_including_pending).toBeDefined();
expect(connections_including_pending.length).toEqual(1);
let exported = await graph.exportUpdates();
expect(exported).toBeDefined();
expect(exported.length).toEqual(1);
});
test('Add a new graph key', async () => {
const environment = { environmentType: environment_1.EnvironmentType.Mainnet };
const graph = new graph_1.Graph(environment);
const dsnpOwnerId = 1;
const x25519_public_key = [
15, 234, 44, 175, 171, 220, 131, 117, 43, 227, 111, 165, 52, 150, 64, 218, 44, 130, 138,
221, 10, 41, 13, 241, 60, 210, 216, 23, 62, 178, 73, 111,
];
const addGraphKeyAction = {
type: "AddGraphKey",
ownerDsnpUserId: dsnpOwnerId,
newPublicKey: new Uint8Array(x25519_public_key),
};
const actions = [];
actions.push(addGraphKeyAction);
const applied = await graph.applyActions(actions);
expect(applied).toEqual(true);
const exported = await graph.exportUpdates();
expect(exported).toBeDefined();
expect(exported.length).toEqual(1);
});
test('Read and deserialize published graph keys', async () => {
let dsnp_key_owner = 1000;
// published keys blobs fetched from blockchain
let published_keys_blob = [
64, 15, 234, 44, 175, 171, 220, 131, 117, 43, 227, 111, 165, 52, 150, 64, 218, 44, 130,
138, 221, 10, 41, 13, 241, 60, 210, 216, 23, 62, 178, 73, 111,
];
let dsnp_keys = {
dsnpUserId: dsnp_key_owner,
keysHash: 100,
keys: [
{
index: 0,
content: new Uint8Array(published_keys_blob),
}
],
};
const environment = { environmentType: environment_1.EnvironmentType.Mainnet };
const graph = new graph_1.Graph(environment);
const deserialized_keys = await graph.deserializeDsnpKeys(dsnp_keys);
expect(deserialized_keys).toBeDefined();
});
//# sourceMappingURL=graph.test.js.map

4

dist/js/index.js

@@ -11,6 +11,6 @@ "use strict";

try {
return require(path_1.default.join(__dirname, "/graphsdk.node"));
return require(path_1.default.join(__dirname, "/dsnp_graph_sdk_node.node"));
}
catch (error) {
throw new Error("Unable to load the native module graphsdk.node");
throw new Error("Unable to load the native module dsnp_graph_sdk_node.node");
}

@@ -17,0 +17,0 @@ }

{
"name": "@dsnp/graph-sdk",
"version": "0.0.0-b34245",
"version": "0.0.0-bfb138",
"author": "Amplica Labs",

@@ -12,6 +12,6 @@ "license": "ISC",

"build": "tsc",
"cp:graphsdk.node": "cp graphsdk.node dist/js/ && cp graphsdk.node js/",
"native:build": "tsc && cargo-cp-artifact -a cdylib graphsdk graphsdk.node -- cargo build --message-format=json-render-diagnostics",
"cp:dsnp_graph_sdk_node.node": "cp dsnp_graph_sdk_node.node dist/js/ && cp dsnp_graph_sdk_node.node js/",
"native:build": "tsc && cargo-cp-artifact -a cdylib dsnp_graph_sdk_node dsnp_graph_sdk_node.node -- cargo build --message-format=json-render-diagnostics",
"native:build-debug": "npm run native:build --",
"native:build-release": "npm run native:build -- --release && npm run cp:graphsdk.node",
"native:build-release": "npm run native:build -- --release && npm run cp:dsnp_graph_sdk_node.node",
"test:cargo": "cargo test",

@@ -52,3 +52,3 @@ "lint": "eslint js/ --ext .ts",

},
"homepage": "https://github.com/LibertyDSNP/graph-sdk#readme"
"homepage": "https://github.com/LibertyDSNP/graph-sdk/bridge/node/README.md"
}

@@ -147,1 +147,196 @@ # DSNP Graph SDK

- `Connection`: Represents a connection between two DSNP users.- `
## Examples
### Create and export a new graph
```typescript
import { Graph, EnvironmentInterface, EnvironmentType } from "@dsnp/graph-sdk";
const environment: EnvironmentInterface = { environmentType: EnvironmentType.Mainnet };
const graph = new Graph(environment);
const public_follow_schema_id = await graph.getSchemaIdFromConfig(environment, ConnectionType.Follow, PrivacyType.Public);
const connect_action = {
type: "Connect",
ownerDsnpUserId: 1,
connection: {
dsnpUserId: 2,
schemaId: public_follow_schema_id,
},
dsnpKeys: {
dsnpUserId: 2,
keysHash: 100,
keys: [],
},
};
await graph.applyActions([connect_action]);
const updates = await graph.exportUpdates();
graph.freeGraphState();
```
### Add a new graph key
```typescript
import { Graph, EnvironmentInterface, EnvironmentType } from "@dsnp/graph-sdk";
const environment: EnvironmentInterface = { environmentType: EnvironmentType.Mainnet };
const graph = new Graph(environment);
const ownerDsnpUserId = 1;
const x25519_public_key = [ 15, 234, 44, 175, 171, 220, 131, 117, 43, 227, 111, 165, 52, 150, 64, 218, 44, 130, 138, 221, 10, 41, 13, 241, 60, 210, 216, 23, 62, 178, 73, 111,];
const addGraphKeyAction = {
type: "AddGraphKey",
ownerDsnpUserId: dsnpOwnerId,
newPublicKey: new Uint8Array(x25519_public_key),
} as AddGraphKeyAction;
await graph.applyActions([addGraphKeyAction]);
const updates = await graph.exportUpdates();
graph.freeGraphState();
```
### Read and deserialize published graph keys
```typescript
import { Graph, EnvironmentInterface, EnvironmentType, DsnpPublicKey } from "@dsnp/graph-sdk";
const environment: EnvironmentInterface = { environmentType: EnvironmentType.Mainnet };
const graph = new Graph(environment);
const dsnpUserId = 1000;
// published keys blobs fetched from blockchain
const published_keys_blob = [ 64, 15, 234, 44, 175, 171, 220, 131, 117, 43, 227, 111, 165, 52, 150, 64, 218, 44, 130, 138, 221, 10, 41, 13, 241, 60, 210, 216, 23, 62, 178, 73, 111,];
let dsnp_keys ={
dsnpUserId: dsnp_key_owner,
keysHash: 100,
keys: [
{
index: 0,
content: new Uint8Array(published_keys_blob),
}
] as KeyData[],
} as DsnpKeys;
const deserialized_keys = await graph.deserializeDsnpKeys(dsnp_keys);
graph.freeGraphState();
```
### Update a Private Follow graph
```typescript
const environment: EnvironmentInterface = { environmentType: EnvironmentType Mainnet };
const graph = new Graph(environment);
const dsnpOwnerId = 1;
const private_follow_graph_schema_id = await graph.getSchemaIdFromConfig(environment, ConnectionType.Follow, PrivacyType.Private);
const import_bundle = {
dsnpUserId: dsnpOwnerId,
schemaId: private_follow_graph_schema_id,
keyPairs: [/* get key-pairs associated with the my_dsnp_user_id user from wallet */],
dsnpKeys: {
dsnpUserId: dsnpOwnerId,
keysHash: 100, // get from blockchain
keys: [/* published keys got from blockchain */],
} as DsnpKeys,
pages: [/* published graph pages got from blockchain */],
} as ImportBundle;
const imported = await graph.importUserData([import_bundle]);
const connect_action: ConnectAction = {
type: "Connect",
ownerDsnpUserId: dsnpOwnerId,
connection: {
dsnpUserId: 2,
schemaId: private_follow_graph_schema_id,
} as Connection,
} as ConnectAction;
const actions = [] as Action[];
actions.push(connect_action);
const applied = await graph.applyActions(actions);
const exported_updates = await graph.exportUpdates();
graph.freeGraphState();
```
### Update a Private Friendship graph
```typescript
const environment: EnvironmentInterface = { environmentType: EnvironmentType Mainnet };
const graph = new Graph(environment);
const dsnpOwnerId = 1;
const private_friendship_graph_schema_id = await graph.getSchemaIdFromConfig(environment, ConnectionType.Friendship, PrivacyType.Private);
const import_bundle = {
dsnpUserId: dsnpOwnerId,
schemaId: private_friendship_graph_schema_id,
keyPairs: [/* get key-pairs associated with the my_dsnp_user_id user from wallet */],
dsnpKeys: {
dsnpUserId: dsnpOwnerId,
keysHash: 100, // get from blockchain
keys: [/* published keys got from blockchain */],
} as DsnpKeys,
pages: [/* published graph pages got from blockchain */],
} as ImportBundle;
const imported = await graph.importUserData([import_bundle]);
// get all associated user without keys so we can fetch and import keys for them
const user_without_keys = await graph.getConnectionsWithoutKeys();
let users_import_bundles = [] as ImportBundle[];
for (const user of user_without_keys) {
let user_dsnp_keys = DsnpKeys {..} // fetch published DsnpKeys for user
let user_pages = .. // fetch published private friendship pages for the user
let user_import_bundle = ImportBundle {
dsnpUserId: user,
schemaId: private_friendship_graph_schema_id,
keyPairs: []. // empty key pairs for user since we don't know and need their secret keys
dsnpKeys: user_dsnp_keys,
pages: user_pages,
} as ImportBundle;
}
const imported = await graph.importUserData(users_import_bundles);
const connect_action: ConnectAction = {
type: "Connect",
ownerDsnpUserId: dsnpOwnerId,
connection: {
dsnpUserId: 2,
schemaId: private_friendship_graph_schema_id,
} as Connection,
dsnKeys: {
dsnpUserId: 2,
keysHash: 100,
keys: [/* get keys from chain for user 2 */],
} as DsnpKeys,
} as ConnectAction;
const actions = [] as Action[];
actions.push(connect_action);
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

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