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

feat(recaps): add proposed api #139

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions packages/recaps/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/abnf.ts
11 changes: 11 additions & 0 deletions packages/recaps/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": ["3box", "3box/jest", "3box/typescript"],
"parserOptions": {
"project": ["tsconfig.lint.json"]
},
"rules": {
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/no-unsafe-assignment": "off"
}
}
4 changes: 4 additions & 0 deletions packages/recaps/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.log
.DS_Store
node_modules
dist
5 changes: 5 additions & 0 deletions packages/recaps/LICENSE-APACHE
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
19 changes: 19 additions & 0 deletions packages/recaps/LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
21 changes: 21 additions & 0 deletions packages/recaps/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
> ⚠️ This package is experimental and based on a specification that is yet to be finalized.

# ReCaps

A library to create and manage ReCaps, including their (de)serialization and human-readable ReCap statements. Follows [EIP-5573](https://github.com/spruceid/EIPs/blob/19dae81ecc8354199bbe28f3b6248851f4cf49cf/EIPS/eip-5573.md) (not finalized).



## Examples

### TODO

```typescript
const recapstr = new Recap({
...
})
```

## License

Dual licensed with APACHE and MIT
22 changes: 22 additions & 0 deletions packages/recaps/jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"moduleFileExtensions": ["js", "json", "ts"],
"testRegex": ".(spec|test).ts$",
"testEnvironment": "node",
"extensionsToTreatAsEsm": [".ts"],
"globals": {
"ts-jest": {
"useESM": true
}
},
"moduleNameMapper": {
"^(\\.{1,2}/.*)\\.js$": "$1"
},
"transform": {
"^.+\\.(t|j)s$": [
"@swc/jest",
{
"root": "../.."
}
]
}
}
57 changes: 57 additions & 0 deletions packages/recaps/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"name": "@didtools/recaps",
"version": "0.0.1",
"description": "Typescript library for ReCaps",
"author": "3Box Labs",
"license": "(Apache-2.0 OR MIT)",
"type": "module",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
".": "./dist/index.js"
},
"files": [
"dist"
],
"engines": {
"node": ">=14.14"
},
"sideEffects": false,
"scripts": {
"build:clean": "del dist",
"build:js": "swc src -d ./dist --config-file ../../.swcrc",
"build:types": "tsc --emitDeclarationOnly --skipLibCheck",
"build": "pnpm run build:clean && pnpm run build:types && pnpm run build:js",
"lint": "eslint src test --fix",
"test": "node --experimental-vm-modules ../../node_modules/jest/bin/jest.js",
"test:ci": "pnpm run test --ci --coverage",
"prepare": "pnpm run build",
"prepublishOnly": "package-check"
},
"repository": {
"type": "git",
"url": "git+https://github.com/ceramicnetwork/js-did.git"
},
"keywords": [
"DID",
"identity",
"OCAP",
"capabilities"
],
"bugs": {
"url": "https://github.com/ceramicnetwork/js-did/issues"
},
"homepage": "https://github.com/ceramicnetwork/js-did#readme",
"dependencies": {
"@ipld/dag-cbor": "^7.0.1",
"apg-js": "^4.1.1",
"caip": "^1.1.0",
"multiformats": "^9.5.1",
"uint8arrays": "^4.0.2"
},
"devDependencies": {
"@types/luxon": "^3.0.0",
"@types/node": "^18.11.7",
"luxon": "^3.0.1"
}
}
93 changes: 93 additions & 0 deletions packages/recaps/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
type CeramicWrite = {
"ceramic/write": []
}
Comment on lines +4 to +6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to keep Ceramic specific things outside of here? Currently all Ceramic specific code of SIWx lives in the js-ceramic codebase.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly likely in the end, but thinking that for now everything ceramic specific goes here for now (to keep more self contained while experimental), and more useful to drive with specific use case first (ceramic), then generalize after

even if specs dont have namespaces, a general library will need to have some form of that, similar to spruce libs, lots of the rules/parsing are defined by that

likely will make sense to combine most of siwx + recap things together instead this separate library here


type Actions = CeramicWrite
type Capability = [string, Actions]
type Capablities = Array<Capability>

function validCeramicTarget(s: string): Uint8Array {
// const modelResource =
// const streamResource =
// const allResource = ""
return true
}

export class ReCap {
_caps: Capablities

constructor(caps:Capablities) {
this._caps = caps
}

/**
* Create ReCap instance from JSON representation
*/
static fromJson(json:Map<string, Actions>):ReCap {
//
}

/**
* Create ReCap instance from URI representation, typically from a SIWX message
*/
static fromURI(recap: string): Recap {

}

/**
* Encode ReCap to ReCap URI (urn:recap:base64url-encoded-recap) to be used in SIWX message
*/
encode():string {
//
}

/**
* Query if this ReCap is valid for a given action and resource/target
*/
can(action: Actions, target: string):boolean {

}

/**
* Generate the human readable ReCap statement for this ReCap, to be used in SIWX message
*/
toStatement():string {

}

/**
* Get JSON representation of ReCap
*/
toJson():Map<string, Actions> {

}

/**
* Add a capability (action & target) to a ReCap, returns new recap
*/
addCapability(action: Actions, target: string):ReCap {

}

/**
* Verify that a ReCap Statement is valid for this ReCap and encodes the same delegations
*/
verifyStatment(statement:string):boolean {

}

/**
* Get array of resources inlcuded in ReCap
*/
get resourceList(): Array<string> {

}

/**
* Get array of actions for given resource/target
*/
get actionsByResource(resource:string): Array<Actions> {

}
}

3 changes: 3 additions & 0 deletions packages/recaps/test/siwe.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
describe('Cacao Auth Verify', () => {
test.todo('Verify')
})
7 changes: 7 additions & 0 deletions packages/recaps/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.build.json",
"compilerOptions": {
"outDir": "./dist"
},
"include": ["src"]
}
4 changes: 4 additions & 0 deletions packages/recaps/tsconfig.lint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.json",
"include": ["src", "test"]
}
6 changes: 4 additions & 2 deletions tsconfig.docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"./packages/key-did-provider-ed25519/src",
"./packages/key-did-provider-secp256k1/src",
"./packages/key-did-resolver/src",
"./packages/pkh-did-resolver/src"
"./packages/pkh-did-resolver/src",
"./packages/recaps/src"
],
"compilerOptions": {
"jsx": "preserve",
Expand All @@ -29,7 +30,8 @@
"./packages/key-did-provider-ed25519/src/index.ts",
"./packages/key-did-provider-secp256k1/src/index.ts",
"./packages/key-did-resolver/src/index.ts",
"./packages/pkh-did-resolver/src/index.ts"
"./packages/pkh-did-resolver/src/index.ts",
"./packages/recaps/src/index.ts"
],
"disableSources": true,
"excludeExternals": true,
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"@didtools/pkh-ethereum": ["packages/pkh-ethereum/src"],
"@didtools/pkh-solana": ["packages/pkh-solana/src"],
"pkh-did-resolver": ["packages/pkh-did-resolver/src"],
"key-did-resolver": ["packages/key-did-resolver/src"]
"key-did-resolver": ["packages/key-did-resolver/src"],
"@didtools/recaps": ["packages/recaps/src"]
}
}
}