generated from nichoth/template-ts-browser
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
84 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,67 @@ | ||
import { test } from '@bicycle-codes/tapzero' | ||
import { example } from '../src/index.js' | ||
import { Parent, Child, Certificate } from '../src/index.js' | ||
import { create as createID } from '@bicycle-codes/identity' | ||
|
||
test('example', async t => { | ||
t.ok('ok', 'should be an example') | ||
example() | ||
const odd = globalThis.webnative | ||
const createProgram = odd.program | ||
|
||
const HOST_URL = 'localhost:1999' | ||
|
||
let _certificate:Certificate|undefined | ||
|
||
test('link 2 devices', async t => { | ||
t.plan(5) | ||
|
||
const alicesProgram = await createProgram({ | ||
namespace: { | ||
name: 'link-tests', | ||
creator: 'tests' | ||
} | ||
}) | ||
const { crypto: alicesCrypto } = alicesProgram.components | ||
const alice = await createID(alicesCrypto, { | ||
humanName: 'alice', | ||
humanReadableDeviceName: 'phone' | ||
}) | ||
|
||
const alicesComputersProgram = await createProgram({ | ||
namespace: { | ||
name: 'link-tests', | ||
creator: 'tests-device-2' | ||
} | ||
}) | ||
|
||
const { crypto: alicesComputersCrypto } = alicesComputersProgram.components | ||
// parent must be called first | ||
Parent(alice, alicesCrypto, { | ||
host: HOST_URL, | ||
code: '1234' | ||
}).then(newId => { | ||
t.ok(newId, 'parent gets a new identity') | ||
}) | ||
|
||
const { identity: childsID, certificate } = await Child( | ||
alicesComputersCrypto, | ||
{ | ||
host: HOST_URL, | ||
code: '1234', | ||
humanReadableDeviceName: 'computer' | ||
} | ||
) | ||
|
||
_certificate = certificate | ||
|
||
t.ok(childsID, 'child gets a new identity') | ||
t.ok(certificate, 'child gets a certificate') | ||
|
||
t.equal(alice.username, childsID.username, | ||
'Both IDs should have the same username') | ||
|
||
t.ok(Object.keys(alice.devices).every(deviceName => { | ||
return childsID.devices[deviceName] | ||
}), 'devices should be equal in both IDs') | ||
}) | ||
|
||
test('the certificate', async t => { | ||
t.equal(_certificate?.recipient) | ||
}) |