Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blob module for Cheqd, improvements for DIDDocument and misc tweaks #459

Merged
merged 12 commits into from
Oct 21, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Corrections
olegnn committed Oct 18, 2024
commit 7964bdd7f7e89726862183b0f72ff4e22b6b0ce9
Original file line number Diff line number Diff line change
@@ -29,7 +29,6 @@ export const DockDidOrDidMethodKey = withQualifier(
*/
async signStateChange(apiProvider, name, payload, keyRef) {
const { LOG_STATE_CHANGE } = process.env;

if (Number(LOG_STATE_CHANGE) || Boolean(LOG_STATE_CHANGE)) {
console.dir(payload, { depth: null });
}
28 changes: 12 additions & 16 deletions packages/credential-sdk/src/types/generic/typed-number.js
Original file line number Diff line number Diff line change
@@ -17,6 +17,18 @@ class TypedNumber extends withBase(class NumberBase {}) {
this.value = num;
}

inc() {
return new this.constructor(++this.value);
}

dec() {
return new this.constructor(--this.value);
}

toJSON() {
return this.value;
}

static from(value) {
if (value instanceof this) {
return value;
@@ -27,22 +39,6 @@ class TypedNumber extends withBase(class NumberBase {}) {
}
}

toJSON() {
return this.value;
}

inc() {
this.value++;

return this;
}

dec() {
this.value--;

return this;
}

static fromJSON(value) {
return new this(value);
}
Original file line number Diff line number Diff line change
@@ -55,33 +55,30 @@ describe("Basic DID tests", () => {
expect(!!dock.account).toBe(true);
});

test("Can create and update document", async () => {
test.only("Can create and update document", async () => {
const did = DockDid.random();

const pair = new Ed25519Keypair(seed);
const publicKey = pair.publicKey();

const verRels = new VerificationRelationship();
const didKey = new DidKey(publicKey, verRels);
const didPair = new DidKeypair([did, 1], pair);

const doc = DIDDocument.create(did, [didKey], [did]);
const doc = DIDDocument.create(did, [didPair.didKey()], [did]);

await modules.did.createDocument(doc);
expect((await modules.did.getDocument(did)).toJSON()).toEqual(doc.toJSON());

const pair2 = Ed25519Keypair.random();
const didKey2 = new DidKey(pair2.publicKey(), verRels);
const didPair2 = new DidKeypair([did, 2], pair2);

const service1 = new ServiceEndpoint("LinkedDomains", [
"ServiceEndpoint#1",
]);

doc
.addServiceEndpoint([did, "service1"], service1)
.addKey([did, 2], didKey2)
.addKey([did, 2], didPair2.didKey())
.removeKey([did, 1]);

await modules.did.updateDocument(doc, new DidKeypair([did, 1], pair));
await modules.did.updateDocument(doc, didPair);

expect((await modules.did.getDocument(did)).toJSON()).toEqual(doc.toJSON());

@@ -92,7 +89,7 @@ describe("Basic DID tests", () => {
doc
.removeServiceEndpoint("service1")
.addServiceEndpoint([did, "service2"], service2);
await modules.did.updateDocument(doc, new DidKeypair([did, 2], pair2));
await modules.did.updateDocument(doc, didPair2);

expect((await modules.did.getDocument(did)).toJSON()).toEqual(doc.toJSON());
});
8 changes: 7 additions & 1 deletion scripts/with_cheqd_docker_test_node
Original file line number Diff line number Diff line change
@@ -12,19 +12,25 @@ docker pull --platform linux/amd64 ghcr.io/cheqd/cheqd-node
# start a pos alice node
alice_container_id=$(docker run --platform linux/amd64 -d --rm --name cheqd-dev -p 26656:26656 -p 26657:26657 -p 1317:1317 -p 9090:9090 -e CHEQD_MNEMONIC="$CHEQD_MNEMONIC" -v $entrypoint:/usr/local/bin/entrypoint.sh -v $config:/tmp/cheqd_config.toml --entrypoint /usr/local/bin/entrypoint.sh ghcr.io/cheqd/cheqd-node start)

cleanup() {
docker kill $alice_container_id
}

try_with_node() {
sleep 10;
# Execute the commands, potentially against the nodes
$@
}

trap cleanup SIGINT

if try_with_node $@; then
exit_code=$?
else
exit_code=$?
fi

# Kill nodes
docker kill $alice_container_id
cleanup

exit $exit_code
8 changes: 7 additions & 1 deletion scripts/with_dock_docker_test_node
Original file line number Diff line number Diff line change
@@ -17,20 +17,26 @@ alice_container_id=$(
--alice --rpc-external --ws-external
)

cleanup() {
docker kill $alice_container_id
}

try_with_node() {
# Wait for nodes to start listening for RPC
"$root_dir"/scripts/wait_for_node_rpc_http
# Execute the commands, potentially against the nodes
$@
}

trap cleanup SIGINT

if try_with_node $@; then
exit_code=$?
else
exit_code=$?
fi

# Kill nodes
docker kill $alice_container_id
cleanup

exit $exit_code

Unchanged files with check annotations Beta

export class DidKeyValueWithRef extends withFrom(
TypedStruct,
function (value, from) {

Check warning on line 229 in packages/credential-sdk/src/types/did/document.js

GitHub Actions / lint

Unexpected unnamed function

Check warning on line 229 in packages/credential-sdk/src/types/did/document.js

GitHub Actions / lint

Unexpected unnamed function
if (typeof value === 'string') {
const [ref, key] = value.split('=');
// eslint-disable-next-line no-use-before-define