Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* 'main' of https://github.com/web3-storage/w3-protocol:
  chore: add ns/* tests (#92)
  chore(master): release w3-store 2.0.0 (#87)
  chore(master): release wallet 1.0.0 (#67)
  • Loading branch information
hugomrdias committed Oct 12, 2022
2 parents 40b5e2f + 93a8ae4 commit 849c13e
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 31 deletions.
4 changes: 2 additions & 2 deletions .github/release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"packages/wallet": "1.0.0",
"packages/access": "2.1.1",
"packages/wallet": "0.3.0",
"packages/access-api": "1.0.0",
"packages/store": "1.1.0"
"packages/store": "2.0.0"
}
108 changes: 101 additions & 7 deletions packages/access/test/capabilities/store.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '../helpers/fixtures.js'

describe('store capabilities', function () {
const proof = delegate({
const any = delegate({
issuer: account,
audience: alice,
capabilities: [
Expand All @@ -23,15 +23,109 @@ describe('store capabilities', function () {
],
})

it('should be able to derive from *', async () => {
const store = delegate({
issuer: account,
audience: alice,
capabilities: [
{
can: 'store/*',
with: account.did(),
},
],
})

it('store/add can be derived from *', async () => {
const add = Store.add.invoke({
issuer: alice,
audience: w3,
with: account.did(),
caveats: {
link: parseLink('bafkqaaa'),
},
proofs: [await any],
})

const result = await access(await add.delegate(), {
capability: Store.add,
principal: Principal,
canIssue: (claim, issuer) => {
return claim.with === issuer
},
})

if (result.error) {
assert.fail(result.message)
}

assert.deepEqual(result.audience.did(), w3.did())
assert.equal(result.capability.can, 'store/add')
assert.deepEqual(result.capability.caveats, {
link: parseLink('bafkqaaa'),
})
})

it('store/add can be derived from store/*', async () => {
const add = Store.add.invoke({
issuer: alice,
audience: w3,
with: account.did(),
caveats: {
link: parseLink('bafkqaaa'),
},
proofs: [await proof],
proofs: [await store],
})

const result = await access(await add.delegate(), {
capability: Store.add,
principal: Principal,
canIssue: (claim, issuer) => {
return claim.with === issuer
},
})

if (result.error) {
assert.fail(result.message)
}

assert.deepEqual(result.audience.did(), w3.did())
assert.equal(result.capability.can, 'store/add')
assert.deepEqual(result.capability.caveats, {
link: parseLink('bafkqaaa'),
})
})

it('store/add can be derived from store/* derived from *', async () => {
const any = await delegate({
issuer: account,
audience: alice,
capabilities: [
{
can: '*',
with: account.did(),
},
],
})

const store = await delegate({
issuer: alice,
audience: bob,
capabilities: [
{
can: 'store/*',
with: account.did(),
},
],
proofs: [any],
})

const add = Store.add.invoke({
issuer: bob,
audience: w3,
with: account.did(),
caveats: {
link: parseLink('bafkqaaa'),
},
proofs: [await store],
})

const result = await access(await add.delegate(), {
Expand Down Expand Up @@ -62,7 +156,7 @@ describe('store capabilities', function () {
caveats: {
size: 1024,
},
proofs: [await proof],
proofs: [await any],
})
.delegate()

Expand Down Expand Up @@ -127,7 +221,7 @@ describe('store capabilities', function () {
for (const size of fixtures) {
const json = JSON.stringify(size)
it(`store/add size must be an int not ${json}`, async () => {
const proofs = [await proof]
const proofs = [await any]
assert.throws(() => {
Store.add.invoke({
issuer: alice,
Expand All @@ -154,7 +248,7 @@ describe('store capabilities', function () {
size,
},
],
proofs: [await proof],
proofs: [await any],
})

const result = await access(add, {
Expand All @@ -171,7 +265,7 @@ describe('store capabilities', function () {
}

it('store/add size must be an int', async () => {
const proofs = [await proof]
const proofs = [await any]
assert.throws(() => {
Store.add.invoke({
issuer: alice,
Expand Down
49 changes: 29 additions & 20 deletions packages/access/test/capabilities/upload.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {

describe('upload capabilities', function () {
// delegation from account to agent
const proof = delegate({
const any = delegate({
issuer: account,
audience: alice,
capabilities: [
Expand All @@ -26,14 +26,23 @@ describe('upload capabilities', function () {
})

it('upload/add can be derived from upload/* derived from *', async () => {
const upload = await Upload.upload
.invoke({
issuer: alice,
audience: bob,
with: account.did(),
proofs: [await any],
})
.delegate()

const add = Upload.add.invoke({
issuer: alice,
issuer: bob,
audience: w3,
with: account.did(),
caveats: {
root: parseLink('bafkqaaa'),
},
proofs: [await proof],
proofs: [upload],
})

const result = await access(await add.delegate(), {
Expand All @@ -60,7 +69,7 @@ describe('upload capabilities', function () {
issuer: alice,
audience: bob,
with: account.did(),
proofs: [await proof],
proofs: [await any],
})

const add = Upload.add.invoke({
Expand Down Expand Up @@ -93,7 +102,7 @@ describe('upload capabilities', function () {
})

it('creating upload/add throws if shards is contains non CAR cid', async () => {
const proofs = [await proof]
const proofs = [await any]
assert.throws(() => {
Upload.add.invoke({
issuer: alice,
Expand Down Expand Up @@ -123,7 +132,7 @@ describe('upload capabilities', function () {
shards: [parseLink('bafkqaaa')],
},
],
proofs: [await proof],
proofs: [await any],
})

const result = await access(add, {
Expand All @@ -148,7 +157,7 @@ describe('upload capabilities', function () {
root: parseLink('bafkqaaa'),
shards: [shard.cid],
},
proofs: [await proof],
proofs: [await any],
})

const result = await access(await add.delegate(), {
Expand Down Expand Up @@ -196,7 +205,7 @@ describe('upload capabilities', function () {
root: parseLink('bafkqaaa'),
},
],
proofs: [await proof],
proofs: [await any],
})

const result = await access(add, {
Expand All @@ -221,7 +230,7 @@ describe('upload capabilities', function () {
audience: bob,
with: account.did(),
caveats: {},
proofs: [await proof],
proofs: [await any],
})
.delegate()

Expand Down Expand Up @@ -263,7 +272,7 @@ describe('upload capabilities', function () {
caveats: {
root: parseLink('bafkqaaa'),
},
proofs: [await proof],
proofs: [await any],
})
.delegate()

Expand Down Expand Up @@ -305,7 +314,7 @@ describe('upload capabilities', function () {
caveats: {
shards: [shard.cid],
},
proofs: [await proof],
proofs: [await any],
})
.delegate()

Expand Down Expand Up @@ -339,7 +348,7 @@ describe('upload capabilities', function () {
issuer: alice,
audience: w3,
with: account.did(),
proofs: [await proof],
proofs: [await any],
})

const result = await access(await list.delegate(), {
Expand All @@ -364,7 +373,7 @@ describe('upload capabilities', function () {
issuer: alice,
audience: bob,
with: account.did(),
proofs: [await proof],
proofs: [await any],
})

const list = Upload.list.invoke({
Expand Down Expand Up @@ -396,7 +405,7 @@ describe('upload capabilities', function () {
issuer: alice,
audience: bob,
with: account.did(),
proofs: [await proof],
proofs: [await any],
})

const list = Upload.list.invoke({
Expand Down Expand Up @@ -445,7 +454,7 @@ describe('upload capabilities', function () {
root: parseLink('bafkqaaa'),
},
],
proofs: [await proof],
proofs: [await any],
})

const result = await access(list, {
Expand All @@ -467,7 +476,7 @@ describe('upload capabilities', function () {
issuer: alice,
audience: w3,
with: account.did(),
proofs: [await proof],
proofs: [await any],
caveats: {
root: parseLink('bafkqaaa'),
},
Expand Down Expand Up @@ -497,7 +506,7 @@ describe('upload capabilities', function () {
issuer: alice,
audience: bob,
with: account.did(),
proofs: [await proof],
proofs: [await any],
})

const remove = Upload.remove.invoke({
Expand Down Expand Up @@ -534,7 +543,7 @@ describe('upload capabilities', function () {
issuer: alice,
audience: bob,
with: account.did(),
proofs: [await proof],
proofs: [await any],
caveats: {
root: parseLink('bafkqaaa'),
},
Expand Down Expand Up @@ -592,7 +601,7 @@ describe('upload capabilities', function () {
root: parseLink('bafkqaaa'),
},
],
proofs: [await proof],
proofs: [await any],
})

const result = await access(remove, {
Expand All @@ -618,7 +627,7 @@ describe('upload capabilities', function () {
caveats: {
root: parseLink('bafkqaaa'),
},
proofs: [await proof],
proofs: [await any],
})
.delegate()

Expand Down
13 changes: 13 additions & 0 deletions packages/store/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog

## [2.0.0](https://github.com/web3-storage/w3-protocol/compare/w3-store-v1.1.0...w3-store-v2.0.0) (2022-10-10)


### ⚠ BREAKING CHANGES

* new accounts (#72)
* awake (#66)

### Features

* awake ([#66](https://github.com/web3-storage/w3-protocol/issues/66)) ([bb66f57](https://github.com/web3-storage/w3-protocol/commit/bb66f5772049e3363a753ea5b336c2fa1e42911e))
* new accounts ([#72](https://github.com/web3-storage/w3-protocol/issues/72)) ([9f6cb41](https://github.com/web3-storage/w3-protocol/commit/9f6cb419d33b9446dd80f8541228096cf2677d45))

## [1.1.0](https://www.github.com/web3-storage/ucanto/compare/w3-store-v1.0.0...w3-store-v1.1.0) (2022-06-24)


Expand Down
2 changes: 1 addition & 1 deletion packages/store/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@web3-storage/store",
"description": "web3.storage upload service",
"version": "1.1.0",
"version": "2.0.0",
"types": "./dist/src/lib.d.ts",
"main": "./src/lib.js",
"keywords": [
Expand Down
Loading

0 comments on commit 849c13e

Please sign in to comment.