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: interface #24

Merged
merged 103 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from 92 commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
40301e9
copy all types
Ad96el Aug 4, 2023
e6d2f3d
integrated messaging
Ad96el Aug 4, 2023
f442317
with messaging
Ad96el Aug 4, 2023
0ab879c
with quote
Ad96el Aug 4, 2023
7008be2
fix: make exportable
Ad96el Aug 7, 2023
5bb1159
fix: test against latest not develop
Ad96el Aug 7, 2023
819d315
fix: test against latest not develop
Ad96el Aug 7, 2023
dcc28a7
refactor: reduce types
Ad96el Aug 8, 2023
0ce054a
refactor: remove jest setup
Ad96el Aug 8, 2023
844cdbf
refactor: restructure
Ad96el Aug 9, 2023
b5042c7
chore: copyright
Ad96el Aug 9, 2023
f66bca6
remove terms
Ad96el Aug 9, 2023
e026d9c
remove newline
Ad96el Aug 9, 2023
d4fb2a0
update imports
Ad96el Aug 9, 2023
3f3aa01
add comments
Ad96el Aug 9, 2023
92f433e
docs docs docs
Ad96el Aug 9, 2023
e7dc7cc
docs docs docs
Ad96el Aug 9, 2023
d1c69c7
feat: type guards
Ad96el Aug 9, 2023
a493e93
feat: generics for message
Ad96el Aug 10, 2023
13b7dcf
feat: type guards
Ad96el Aug 10, 2023
7cc83fa
fmt
Ad96el Aug 10, 2023
7670f94
feat: errors
Ad96el Aug 10, 2023
0c97d2b
feat: catch
Ad96el Aug 10, 2023
6bfd5d8
refactor: errors
Ad96el Aug 10, 2023
878fe28
feat: default type
Ad96el Aug 10, 2023
d2627c3
test: github action
Ad96el Aug 11, 2023
a13d67f
fix: workflow
Ad96el Aug 11, 2023
99bbc0c
fmt
Ad96el Aug 11, 2023
09c5990
chore: license
Ad96el Aug 11, 2023
efcd4b5
newline
Ad96el Aug 11, 2023
7ebb031
refactor: change return type
Ad96el Aug 11, 2023
00a9738
feat: add did uri
Ad96el Aug 11, 2023
d8a29fe
add test case
Ad96el Aug 11, 2023
075d91a
wording
Ad96el Aug 11, 2023
2e6f8c7
first prototype
Ad96el Aug 14, 2023
1aa812a
newline
Ad96el Aug 11, 2023
792dc5d
refactor: change return type
Ad96el Aug 11, 2023
1b23e4c
fmt
Ad96el Aug 14, 2023
b0bb518
fix tests
Ad96el Aug 14, 2023
ce709a9
intermediate prototype
Ad96el Aug 16, 2023
d5bc54d
finished credential workflow
Ad96el Aug 17, 2023
7db695a
feat: finished workflows
Ad96el Aug 21, 2023
2df8dff
first tests
Ad96el Aug 21, 2023
c76cc9b
change response
Ad96el Aug 21, 2023
dfaafcd
fix tests
Ad96el Aug 22, 2023
22073b2
namespace
Ad96el Aug 22, 2023
9672d48
tests for session
Ad96el Aug 23, 2023
e06c1ec
do not export verifyMessageEnvelope
Ad96el Aug 23, 2023
0a2ffb9
reduce interface
Ad96el Aug 23, 2023
3969f72
change body type
Ad96el Aug 23, 2023
6606e0d
tests for verifier and setup for attestation
Ad96el Aug 23, 2023
d26a9ef
revert
Ad96el Aug 23, 2023
b5316c5
remove comments
Ad96el Aug 23, 2023
64f5d52
message body
Ad96el Aug 23, 2023
ffdea2c
mostly attestation
Ad96el Aug 24, 2023
7d348a0
from body generic
Ad96el Aug 24, 2023
c36184f
finished tests
Ad96el Aug 24, 2023
5e20bda
format
Ad96el Aug 24, 2023
34a178d
changed config file
Ad96el Aug 24, 2023
c3ed494
Merge branch 'refactor/messaging' into interface
Ad96el Aug 24, 2023
51e3b01
refactor interface
Ad96el Aug 25, 2023
a28ac4c
refactor interface
Ad96el Aug 25, 2023
16bc76e
updated attestation tests
Ad96el Aug 28, 2023
cafbe0c
remove newline
Ad96el Aug 28, 2023
40b99e5
fix verifiers
Ad96el Aug 28, 2023
004f13d
fmt
Ad96el Aug 28, 2023
0d1202c
intermediate prototype
Ad96el Aug 28, 2023
1159e23
check tx
Ad96el Aug 29, 2023
af9eb1c
remove imports
Ad96el Aug 29, 2023
0f45ef2
add misc message
Ad96el Aug 29, 2023
7a8790b
adjust timeout for github action
Ad96el Aug 29, 2023
7baf43a
docs: add docs to interface
Ad96el Aug 31, 2023
329edc2
disconnect in tests
Ad96el Aug 31, 2023
8802245
remove after_all
Ad96el Aug 31, 2023
614406b
remove import
Ad96el Aug 31, 2023
4b50a41
building
Ad96el Sep 14, 2023
d6e3cdf
clean up
Ad96el Sep 14, 2023
9ff643e
Merge branch 'main' into interface
Ad96el Oct 30, 2023
5afc7bb
make esm default
Ad96el Oct 30, 2023
b6cd7a7
Update LICENSE
Ad96el Oct 30, 2023
265825f
remove comment
Ad96el Oct 30, 2023
158fa78
refactr apiAt
Ad96el Oct 30, 2023
76b5f05
split the steps
Ad96el Oct 30, 2023
9db3774
improved error message
Ad96el Oct 30, 2023
4dcd647
remove debugging
Ad96el Oct 30, 2023
eeb314e
add early return
Ad96el Oct 30, 2023
83fa15b
add return type
Ad96el Oct 30, 2023
a9f883d
changed test command
Ad96el Oct 30, 2023
81987ea
fmt
Ad96el Oct 30, 2023
a9ece08
test if ctype exists
Ad96el Oct 30, 2023
24ee6a0
test if ctype exists
Ad96el Oct 30, 2023
d28ec83
update sdk
Ad96el Oct 31, 2023
b84715d
Merge branch 'main' into interface
Ad96el Nov 1, 2023
34572c1
lockfile
Ad96el Nov 1, 2023
8de544c
add lockfile
Ad96el Nov 1, 2023
5c45338
add lockfile
Ad96el Nov 1, 2023
6ba0c82
tests
Ad96el Nov 1, 2023
bd6488a
fmt
Ad96el Nov 1, 2023
3299408
add types
Ad96el Nov 1, 2023
9dfd73a
package.json
Ad96el Nov 1, 2023
0831e80
prettier
Ad96el Nov 1, 2023
521f520
jest config
Ad96el Nov 1, 2023
2076c2c
jest config
Ad96el Nov 1, 2023
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
26 changes: 5 additions & 21 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,16 @@
"browser": true,
"es2021": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"plugins": ["@typescript-eslint"],
"rules": {

"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"never"
]
"linebreak-style": ["error", "unix"],
"quotes": ["error", "single"],
"semi": ["error", "never"]
}
}
29 changes: 29 additions & 0 deletions .github/workflows/code-format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Code Format Check

on:
push:
branches:
- '*'
pull_request:
branches:
- '*'

jobs:
format-check:
name: Prettier Format Check
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: '16'

- name: Install dependencies
run: yarn install

- name: Run Prettier check
run: yarn prettier --check .
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: 16
cache: "yarn"
cache: 'yarn'

- name: yarn install
run: yarn install --immutable
Expand All @@ -34,7 +34,7 @@ jobs:
run: docker pull $IMG_NAME

- name: run tests
timeout-minutes: 5
timeout-minutes: 10
env:
TESTCONTAINERS_NODE_IMG: ${{ env.IMG_NAME }}
run: |
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
yarn.lock
yarn-error.log
/.vscode

/dist
*.js
*.d.ts
8 changes: 4 additions & 4 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"trailingComma": "es5",
"semi": false,
"singleQuote": true,
"tabWidth": 2
"trailingComma": "es5",
"semi": false,
"singleQuote": true,
"tabWidth": 2
}
Dudleyneedham marked this conversation as resolved.
Show resolved Hide resolved
9 changes: 5 additions & 4 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Copyright (c) 2022-2023, BOTLabs GmbH
All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. All advertising materials mentioning features or use of this software must display the following acknowledgement: This product includes software developed by the BOTLabs GmbH.
4. Neither the name of the BOTLabs GmbH nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. All advertising materials mentioning features or use of this software must display the following acknowledgement: This product includes software developed by the BOTLabs GmbH.
4. Neither the name of the BOTLabs GmbH nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY BOTLABS GMBH ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BOTLABS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8 changes: 7 additions & 1 deletion jest.config.js → jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,11 @@ module.exports = {
collectCoverageFrom: ['**/*/src/**/*.ts'],
rootDir: 'src',
coverageDirectory: 'coverage',
moduleDirectories: ['node_modules'],
moduleDirectories: ['dist', 'node_modules'],
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think there is a dist directory now

globals: {
'ts-jest': {
tsconfig: 'tsconfig.cjs.json',
},
},
resolver: 'ts-jest-resolver',
}
37 changes: 17 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,39 +1,35 @@
{
"name": "kilt-extension-api",
"version": "0.1.0",
"main": "./index.js",
"types": "./index.d.ts",
"type": "commonjs",
"main": "./dist/cjs/index.js",
"types": "./dist/cjs/index.d.ts",
"type": "module",
"exports": {
".": {
"types": "./index.d.ts",
"default": "./index.js"
},
"./wellKnownDidConfiguration": {
"types": "./wellKnownDidConfiguration/index.d.ts",
"default": "./wellKnownDidConfiguration/index.js"
},
"./types": {
"types": "./types/index.d.ts"
}
"import": "./dist/esm/index.js",
"require": "./dist/cjs/index.js",
"default": "./dist/cjs/index.js"
},
"author": "KILT <[email protected]>",
"license": "BSD-4-Clause",
"scripts": {
"lint": "eslint --ext .ts .",
"build": "tsc -p tsconfig.build.json",
"build": "yarn build:cjs && yarn build:esm",
"build:cjs": "tsc -p tsconfig.cjs.json",
"build:esm": "tsc -p tsconfig.json",
"clean": "exec git clean -xf -e 'node_modules' '*'",
rflechtner marked this conversation as resolved.
Show resolved Hide resolved
"test": "jest test"
"test": "jest test --detectOpenHandles --forceExit"
},
"dependencies": {
"@kiltprotocol/sdk-js": "^0.33.1",
"@kiltprotocol/types": "^0.33.1",
"@kiltprotocol/vc-export": "^0.33.1",
"@kiltprotocol/sdk-js": "^0.34.0",
"@kiltprotocol/types": "^0.34.0",
"@kiltprotocol/vc-export": "^0.34.0",
"@polkadot/keyring": "^12.3.2",
"@polkadot/util": "^12.3.2",
Dudleyneedham marked this conversation as resolved.
Show resolved Hide resolved
"prettier": "^3.0.1",
"yargs": "^17.7.2"
},
"devDependencies": {
"ts-jest-resolver": "^2.0.1",
"@polkadot/util-crypto": "^12.3.2",
"@types/jest": "^28.0.0",
"@types/node": "^18.8.2",
Expand All @@ -52,5 +48,6 @@
},
"bin": {
"createDidConfig": "./cli/createDidConfig.js"
}
},
"repository": {}
rflechtner marked this conversation as resolved.
Show resolved Hide resolved
}
Dudleyneedham marked this conversation as resolved.
Show resolved Hide resolved
11 changes: 9 additions & 2 deletions src/cli/createDidConfig.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#!/usr/bin/env node

/**
* Copyright (c) 2018-2023, BOTLabs GmbH.
*
* This source code is licensed under the BSD 4-Clause "Original" license
* found in the LICENSE file in the root directory of this source tree.
*/

import { Credential, Did, connect, disconnect } from '@kiltprotocol/sdk-js'
import { DidResourceUri, DidUri, ICredentialPresentation, SignCallback } from '@kiltprotocol/types'

Expand All @@ -9,8 +16,8 @@ import { u8aEq } from '@polkadot/util'
import { readFile, writeFile } from 'fs/promises'
import yargs from 'yargs/yargs'

import { didConfigResourceFromCredential, createCredential } from '../wellKnownDidConfiguration'
import { DidConfigResource } from '../types'
import { didConfigResourceFromCredential, createCredential } from '../wellKnownDidConfiguration/index.js'
import { DidConfigResource } from '../types/index.js'

type KeyType = 'sr25519' | 'ed25519' | 'ecdsa'

Expand Down
2 changes: 1 addition & 1 deletion src/getExtension/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ApiWindow, InjectedWindowProvider, PubSubSessionV1, PubSubSessionV2 } from '../types'
import { ApiWindow, InjectedWindowProvider, PubSubSessionV1, PubSubSessionV2 } from '../types/index.js'

rflechtner marked this conversation as resolved.
Show resolved Hide resolved
// cross-environment reference to global object (aka 'window' in browser environments)
const apiWindow = globalThis as Window & ApiWindow
Expand Down
7 changes: 4 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { getExtensions, watchExtensions, initializeKiltExtensionAPI } from './getExtension'
export * as Message from './messaging'
export * as Quote from './quote'
export * as Message from './messaging/index.js'
export * as Quote from './quote/index.js'

export { getExtensions, watchExtensions, initializeKiltExtensionAPI } from './getExtension/index.js'
12 changes: 8 additions & 4 deletions src/messaging/CredentialApiMessageType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ import {
isRejectAttestation,
isSubmitCredential,
isIRequestCredential,
} from '../utils'
import { verifyMessageEnvelope } from './MessageEnvelope'
import * as MessageError from './Error'
import type { IMessage, CredentialApiMessageBody } from '../types'
isIRequestPayment,
isIConfirmPayment,
} from '../utils/index.js'
import * as MessageError from './Error.js'
import type { IMessage, CredentialApiMessageBody } from '../types/index.js'
import { verifyMessageEnvelope } from './MessageEnvelope.js'

/**
* Checks if the message body is well-formed.
Expand Down Expand Up @@ -67,6 +69,8 @@ export function assertKnownMessageBody(message: IMessage): void {
throw new MessageError.SignatureMalformedError()
}
})
} else if (isIRequestPayment(message) || isIConfirmPayment(message)) {
return
} else {
throw new MessageError.UnknownMessageBodyTypeError()
}
Expand Down
1 change: 1 addition & 0 deletions src/messaging/Error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export declare class UnknownMessageBodyTypeError extends MessageError {}
export declare class DecodingMessageError extends MessageError {}
export declare class CTypeUnknownPropertiesError extends MessageError {}
export declare class InvalidDidFormatError extends MessageError {}
export declare class KeyError extends MessageError {}
export declare class DidError extends MessageError {
constructor(context?: string, type?: string)
}
Expand Down
11 changes: 7 additions & 4 deletions src/messaging/MessageEnvelope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

import { DecryptCallback, DidResolveKey, DidResourceUri, EncryptCallback } from '@kiltprotocol/types'
import * as Did from '@kiltprotocol/did'
import * as MessageError from './Error'
import * as MessageError from './Error.js'
import { hexToU8a, stringToU8a, u8aToHex, u8aToString } from '@polkadot/util'

import type { IEncryptedMessage, IEncryptedMessageContents, IMessage } from '../types'
import type { IEncryptedMessage, IEncryptedMessageContents, IMessage } from '../types/index.js'

/**
* Checks if the message object is well-formed.
Expand Down Expand Up @@ -94,14 +94,17 @@ export async function decrypt(

verifyMessageEnvelope(decrypted)
if (sender !== senderKeyDetails.controller) {
throw new MessageError.IdentityMismatchError('Encryption key', 'Sender')
throw new MessageError.IdentityMismatchError(
'Encryption key',
`Sender: ${sender}, found: ${senderKeyDetails.controller}`
)
}

return decrypted
}

/**
* Encrypts the [[Message]] as a string. This can be reversed with [[decrypt]].
* Encrypts the [[Message]] as a string.
*
* @param message The message to encrypt.
* @param encryptCallback The callback to encrypt with the secret key.
Expand Down
8 changes: 4 additions & 4 deletions src/messaging/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Messages are encrypted using authenticated encryption: the two parties authenticate to each other, but the message authentication provides repudiation possibilities.
*/

export { fromBody } from './utils'
export { encrypt, decrypt } from './MessageEnvelope'
export { assertKnownMessage } from './CredentialApiMessageType'
export * from './Error'
export { fromBody } from './utils.js'
export { encrypt, decrypt } from './MessageEnvelope.js'
export { assertKnownMessage } from './CredentialApiMessageType.js'
export * from './Error.js'
Loading
Loading