-
Notifications
You must be signed in to change notification settings - Fork 6
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
1 parent
ae5f7a9
commit a356eb9
Showing
13 changed files
with
15,530 additions
and
12,397 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
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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { test } from '../helpers/context.js' | ||
import { createUcanLogObject } from '../../service/index.js' | ||
|
||
import * as Signer from '@ucanto/principal/ed25519' | ||
import { CAR, CBOR } from '@ucanto/transport' | ||
import * as DAGJSON from '@ipld/dag-json' | ||
import * as UCAN from '@ipld/dag-ucan' | ||
import { fromString as uint8arrayFromString } from 'uint8arrays/from-string' | ||
|
||
import { createSpace } from '../helpers/ucanto.js' | ||
|
||
test('writes invocation to ucan log table', async t => { | ||
const uploadService = await Signer.generate() | ||
const alice = await Signer.generate() | ||
const { proof, spaceDid } = await createSpace(alice) | ||
|
||
const data = new Uint8Array([11, 22, 34, 44, 55]) | ||
const link = await CAR.codec.link(data) | ||
const nb = { link, size: data.byteLength } | ||
const can = 'store/add' | ||
|
||
const request = await CAR.encode([ | ||
{ | ||
issuer: alice, | ||
audience: uploadService, | ||
capabilities: [{ | ||
can, | ||
with: spaceDid, | ||
nb | ||
}], | ||
proofs: [proof], | ||
} | ||
]) | ||
|
||
|
||
// @ts-expect-error different type interface in AWS expected request | ||
const ucanLogObj = await createUcanLogObject(request) | ||
|
||
const requestCar = await CAR.codec.decode(request.body) | ||
const requestCarRootCid = requestCar.roots[0].cid | ||
|
||
t.is(ucanLogObj.root, requestCarRootCid.toString()) | ||
t.truthy(ucanLogObj.bytes) | ||
t.truthy(ucanLogObj.value) | ||
|
||
// Decode and validate bytes | ||
const streamCar = await CAR.codec.decode(uint8arrayFromString(ucanLogObj.bytes)) | ||
// @ts-expect-error UCAN.View<UCAN.Capabilities> inferred as UCAN.View<unknown> | ||
const ucan = UCAN.decode(streamCar.roots[0].bytes) | ||
|
||
t.is(ucan.iss.did(), alice.did()) | ||
t.is(ucan.aud.did(), uploadService.did()) | ||
t.deepEqual(ucan.prf, [proof.root.cid]) | ||
t.is(ucan.att.length, 1) | ||
t.like(ucan.att[0], { | ||
nb, | ||
can, | ||
with: spaceDid, | ||
}) | ||
|
||
// Decode and validate value | ||
const jsonDecodedUcan = DAGJSON.decode(uint8arrayFromString(ucanLogObj.value)) | ||
const cborEncoded = CBOR.codec.encode(jsonDecodedUcan) | ||
const ucanFromJson = UCAN.decode(cborEncoded) | ||
|
||
t.is(ucanFromJson.iss.did(), alice.did()) | ||
t.is(ucanFromJson.aud.did(), uploadService.did()) | ||
t.deepEqual(ucanFromJson.prf, [proof.root.cid]) | ||
t.is(ucanFromJson.att.length, 1) | ||
t.like(ucanFromJson.att[0], { | ||
nb, | ||
can, | ||
with: spaceDid, | ||
}) | ||
}) |
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
Oops, something went wrong.