From 4aceabdf820432b12e0c78de770d532acdf39201 Mon Sep 17 00:00:00 2001 From: Rodolfo Miranda Date: Tue, 22 Aug 2023 22:14:00 -0300 Subject: [PATCH 1/4] apping oobis endrole --- test/app/apping.test.ts | 20 ++++++++++++++++++ test/app/signify.test.ts | 45 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 test/app/apping.test.ts diff --git a/test/app/apping.test.ts b/test/app/apping.test.ts new file mode 100644 index 00000000..8784df30 --- /dev/null +++ b/test/app/apping.test.ts @@ -0,0 +1,20 @@ +import {strict as assert} from "assert"; +import {randomPasscode, randomNonce} from '../../src/keri/app/apping' +import libsodium from "libsodium-wrappers-sumo" + +describe('Controller', () => { + it('Random passcode', async () => { + await libsodium.ready; + let passcode = randomPasscode() + assert.equal(passcode.length, 22) + }) + + it('Random nonce', async () => { + await libsodium.ready; + let nonce = randomNonce() + assert.equal(nonce.length, 44) + }) + + + +}) \ No newline at end of file diff --git a/test/app/signify.test.ts b/test/app/signify.test.ts index b49ff6c9..297c9c81 100644 --- a/test/app/signify.test.ts +++ b/test/app/signify.test.ts @@ -316,6 +316,20 @@ describe('SignifyClient', () => { assert.deepEqual(lastBody.ixn,{"v":"KERI10JSON000138_","t":"ixn","d":"EPtNJLDft3CB-oz3qIhe86fnTKs-GYWiWyx8fJv3VO5e","i":"ELUvZ8aJEHAQE-0nsevyYTP98rBbGJUrTj5an-pCmwrK","s":"1","p":"ELUvZ8aJEHAQE-0nsevyYTP98rBbGJUrTj5an-pCmwrK","a":[{"i":"ELUvZ8aJEHAQE-0nsevyYTP98rBbGJUrTj5an-pCmwrK","s":0,"d":"ELUvZ8aJEHAQE-0nsevyYTP98rBbGJUrTj5an-pCmwrK"}]}) assert.deepEqual(lastBody.sigs,["AADEzKk-5LT6vH-PWFb_1i1A8FW-KGHORtTOCZrKF4gtWkCr9vN1z_mDSVKRc6MKktpdeB3Ub1fWCGpnS50hRgoJ"]) + await client.identifiers().addEndRole('aid1','agent') + lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length-1]! + lastBody = JSON.parse(lastCall[1]!.body!.toString()) + assert.equal(lastCall[0]!,url+'/identifiers/aid1/endroles') + assert.equal(lastCall[1]!.method,'POST') + assert.equal(lastBody.rpy.t,'rpy') + assert.equal(lastBody.rpy.r,'/end/role/add') + assert.deepEqual(lastBody.rpy.a,{"cid":"ELUvZ8aJEHAQE-0nsevyYTP98rBbGJUrTj5an-pCmwrK","role":"agent"}) + + await client.identifiers().members('aid1') + lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length-1]! + assert.equal(lastCall[0]!,url+'/identifiers/aid1/members') + assert.equal(lastCall[1]!.method,'GET') + }) it('Randy identifiers', async () => { @@ -385,7 +399,38 @@ describe('SignifyClient', () => { assert.equal(lastCall[0]!,url+'/schema/'+schemaSAID) assert.equal(lastCall[1]!.method,'GET') + }) + + it('OOBIs', async () => { + await libsodium.ready; + const bran = "0123456789abcdefghijk" + let client = new SignifyClient(url, bran, Tier.low, boot_url) + + await client.boot() + await client.connect() + + let oobis = client.oobis() + + await oobis.get("aid","agent") + let lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length-1]! + assert.equal(lastCall[0]!,url+'/identifiers/aid/oobis?role=agent') + assert.equal(lastCall[1]!.method,'GET') + + await oobis.resolve("http://oobiurl.com") + lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length-1]! + let lastBody = JSON.parse(lastCall[1]!.body!.toString()) + assert.equal(lastCall[0]!,url+'/oobis') + assert.equal(lastCall[1]!.method,'POST') + assert.deepEqual(lastBody.url,"http://oobiurl.com") + + await oobis.resolve("http://oobiurl.com","witness") + lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length-1]! + lastBody = JSON.parse(lastCall[1]!.body!.toString()) + assert.equal(lastCall[0]!,url+'/oobis') + assert.equal(lastCall[1]!.method,'POST') + assert.deepEqual(lastBody.url,"http://oobiurl.com") + assert.deepEqual(lastBody.oobialias,"witness") }) }) \ No newline at end of file From c1fc9e8c0b6d64297a8540df0f365089a8ba7e60 Mon Sep 17 00:00:00 2001 From: Rodolfo Miranda Date: Tue, 22 Aug 2023 22:18:04 -0300 Subject: [PATCH 2/4] operations --- test/app/signify.test.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/app/signify.test.ts b/test/app/signify.test.ts index 297c9c81..0ba8d162 100644 --- a/test/app/signify.test.ts +++ b/test/app/signify.test.ts @@ -431,6 +431,26 @@ describe('SignifyClient', () => { assert.equal(lastCall[1]!.method,'POST') assert.deepEqual(lastBody.url,"http://oobiurl.com") assert.deepEqual(lastBody.oobialias,"witness") + + }) + + it('Operations', async () => { + await libsodium.ready; + const bran = "0123456789abcdefghijk" + + let client = new SignifyClient(url, bran, Tier.low, boot_url) + + await client.boot() + await client.connect() + + let ops = client.operations() + + await ops.get("operationName") + let lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length-1]! + assert.equal(lastCall[0]!,url+'/operations/operationName') + assert.equal(lastCall[1]!.method,'GET') + + }) }) \ No newline at end of file From 0ba7ca5fa279db11c9c0e0cd7e9e42448a802a25 Mon Sep 17 00:00:00 2001 From: Rodolfo Miranda Date: Tue, 22 Aug 2023 22:57:34 -0300 Subject: [PATCH 3/4] some creds --- src/keri/app/signify.ts | 2 +- test/app/signify.test.ts | 68 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/src/keri/app/signify.ts b/src/keri/app/signify.ts index 569842fa..93bd3fb4 100644 --- a/src/keri/app/signify.ts +++ b/src/keri/app/signify.ts @@ -939,7 +939,7 @@ export class KeyStates { * @param {Array} pres List of identifier prefixes * @returns {Promise} A promise to the key states */ - async list(pres: [string]): Promise { + async list(pres: string[]): Promise { let path = `/states?${pres.map(pre => `pre=${pre}`).join('&')}` let data = null let method = 'GET' diff --git a/test/app/signify.test.ts b/test/app/signify.test.ts index 0ba8d162..00c8997b 100644 --- a/test/app/signify.test.ts +++ b/test/app/signify.test.ts @@ -453,4 +453,72 @@ describe('SignifyClient', () => { }) + it('Events and states', async () => { + await libsodium.ready; + const bran = "0123456789abcdefghijk" + + let client = new SignifyClient(url, bran, Tier.low, boot_url) + + await client.boot() + await client.connect() + + let keyEvents = client.keyEvents() + let keyStates = client.keyStates() + + await keyEvents.get("EP10ooRj0DJF0HWZePEYMLPl-arMV-MAoTKK-o3DXbgX") + let lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length-1]! + assert.equal(lastCall[0]!,url+'/events?pre=EP10ooRj0DJF0HWZePEYMLPl-arMV-MAoTKK-o3DXbgX') + assert.equal(lastCall[1]!.method,'GET') + + await keyStates.get("EP10ooRj0DJF0HWZePEYMLPl-arMV-MAoTKK-o3DXbgX") + lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length-1]! + assert.equal(lastCall[0]!,url+'/states?pre=EP10ooRj0DJF0HWZePEYMLPl-arMV-MAoTKK-o3DXbgX') + assert.equal(lastCall[1]!.method,'GET') + + await keyStates.list(["EP10ooRj0DJF0HWZePEYMLPl-arMV-MAoTKK-o3DXbgX","ELUvZ8aJEHAQE-0nsevyYTP98rBbGJUrTj5an-pCmwrK"]) + lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length-1]! + assert.equal(lastCall[0]!,url+'/states?pre=EP10ooRj0DJF0HWZePEYMLPl-arMV-MAoTKK-o3DXbgX&pre=ELUvZ8aJEHAQE-0nsevyYTP98rBbGJUrTj5an-pCmwrK') + assert.equal(lastCall[1]!.method,'GET') + + await keyStates.query("EP10ooRj0DJF0HWZePEYMLPl-arMV-MAoTKK-o3DXbgX",1,"EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao") + lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length-1]! + let lastBody = JSON.parse(lastCall[1]!.body!.toString()) + assert.equal(lastCall[0]!,url+'/queries') + assert.equal(lastCall[1]!.method,'POST') + assert.equal(lastBody.pre,"EP10ooRj0DJF0HWZePEYMLPl-arMV-MAoTKK-o3DXbgX") + assert.equal(lastBody.sn,1) + assert.equal(lastBody.anchor,"EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao") + }) + + it('Credentials', async () => { + await libsodium.ready; + const bran = "0123456789abcdefghijk" + + let client = new SignifyClient(url, bran, Tier.low, boot_url) + + await client.boot() + await client.connect() + + let credentials = client.credentials() + + let kargs = { + filter:{"-i": {"$eq": "EP10ooRj0DJF0HWZePEYMLPl-arMV-MAoTKK-o3DXbgX"}}, + sort: [{"-s": 1}], + limit: 25, + skip: 5 + } + await credentials.list("aid1",kargs) + let lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length-1]! + let lastBody = JSON.parse(lastCall[1]!.body!.toString()) + assert.equal(lastCall[0]!,url+'/identifiers/aid1/credentials/query') + assert.equal(lastCall[1]!.method,'POST') + assert.deepEqual(lastBody,kargs) + + await credentials.get("aid1","EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao",true) + lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length-1]! + assert.equal(lastCall[0]!,url+'/identifiers/aid1/credentials/EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao') + assert.equal(lastCall[1]!.method,'GET') + + }) + }) \ No newline at end of file From 64d3ceb0c7be0b1557cbfb8588d12074d1c065c3 Mon Sep 17 00:00:00 2001 From: Rodolfo Miranda Date: Tue, 22 Aug 2023 23:13:58 -0300 Subject: [PATCH 4/4] contacts --- test/app/signify.test.ts | 49 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/test/app/signify.test.ts b/test/app/signify.test.ts index 00c8997b..69498a95 100644 --- a/test/app/signify.test.ts +++ b/test/app/signify.test.ts @@ -521,4 +521,53 @@ describe('SignifyClient', () => { }) + it('Contacts', async () => { + await libsodium.ready; + const bran = "0123456789abcdefghijk" + + let client = new SignifyClient(url, bran, Tier.low, boot_url) + + await client.boot() + await client.connect() + + let contacts = client.contacts() + + + await contacts.list("mygroup","company","mycompany") + let lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length-1]! + assert.equal(lastCall[0]!,url+'/contacts?group=mygroup&company=mycompany') + assert.equal(lastCall[1]!.method,'GET') + + + await contacts.get("EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao") + lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length-1]! + assert.equal(lastCall[0]!,url+'/contacts/EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao') + assert.equal(lastCall[1]!.method,'GET') + + let info = { + "name": "John Doe", + "company": "My Company" + } + await contacts.add("EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao",info) + lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length-1]! + let lastBody = JSON.parse(lastCall[1]!.body!.toString()) + assert.equal(lastCall[0]!,url+'/contacts/EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao') + assert.equal(lastCall[1]!.method,'POST') + assert.deepEqual(lastBody,info) + + await contacts.update("EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao",info) + lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length-1]! + lastBody = JSON.parse(lastCall[1]!.body!.toString()) + assert.equal(lastCall[0]!,url+'/contacts/EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao') + assert.equal(lastCall[1]!.method,'PUT') + assert.deepEqual(lastBody,info) + + await contacts.delete("EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao") + lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length-1]! + lastBody = JSON.parse(lastCall[1]!.body!.toString()) + assert.equal(lastCall[0]!,url+'/contacts/EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao') + assert.equal(lastCall[1]!.method,'DELETE') + + }) + }) \ No newline at end of file