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

rename to uHTTP #4

Merged
merged 9 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 8 additions & 0 deletions .changeset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changesets

Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)

We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
11 changes: 11 additions & 0 deletions .changeset/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://unpkg.com/@changesets/config@3.0.1/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "restricted",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
5 changes: 5 additions & 0 deletions .changeset/curly-hotels-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hoprnet/uhttp-crypto': patch
---

initial uHTTP
7 changes: 5 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ on:
workflow_dispatch:
inputs:
tag:
type: string
type: choice
options:
- latest
- beta
required: true
default: latest
default: beta

jobs:
publish:
Expand Down
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# pHTTP-crypto
# u(nlinked)HTTP-crypto

p(rivate)HTTP crypto library
Provides encryption and decryption functionality for uHTTP.

Provides encryption and decryption functionality for pHTTP.
## Deployment

### Staging

- staging can be deployed from main
- run `yarn changeset version` to create the current changelog
- commit everything, create a matching tag and push to main
- run publish action with `beta`(default) tag

### Production

- production must be deployed from main
- should come after a successful staging publishing
- run publish action with `latest` tag
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@hoprnet/phttp-crypto",
"name": "@hoprnet/uhttp-crypto",
"version": "1.0.0",
"description": "privateHTTP crypto protocol",
"description": "u(nlinked)HTTP crypto protocol",
"author": "HOPR Association",
"main": "./build/index.js",
"types": "./build/index.d.ts",
Expand All @@ -10,7 +10,7 @@
],
"keywords": [
"hopr",
"pHTTP"
"uHTTP"
],
"engines": {
"node": ">=18.0.0"
Expand All @@ -25,6 +25,7 @@
"test": "jest --coverage"
},
"devDependencies": {
"@changesets/cli": "^2.27.5",
"@stylistic/eslint-plugin": "^1.5.4",
"@types/jest": "^29.5.11",
"@types/node": "^20.11.27",
Expand Down
30 changes: 15 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export type ResFailed = { res: ResState.Failed; error: string };

export type Result = ResOk | ResFailed;

/// pHTTP Crypto protocol version
export const pHTTP_CRYPTO_VERSION = 0x21;
/// uHTTP Crypto protocol version
export const uHTTP_CRYPTO_VERSION = 0x21;

/// Encoded public key size |W|
const PUBLIC_KEY_SIZE_ENCODED = 33;
Expand Down Expand Up @@ -86,7 +86,7 @@ function initializeCipher(
// Construct salt for the HKDF
const textEnc = new TextEncoder();
const salt = new Uint8Array(1 + peerId.length + saltTag.length);
salt[0] = pHTTP_CRYPTO_VERSION;
salt[0] = uHTTP_CRYPTO_VERSION;
salt.set(textEnc.encode(peerId), 1);
salt.set(textEnc.encode(saltTag), peerId.length + 1);

Expand Down Expand Up @@ -125,9 +125,9 @@ function generateEphemeralKey(randomFn: (len: number) => Uint8Array) {
return { pubKey, privKey };
}

/// Called by the pHTTP client
/// Takes enveloped request data, the public key of the pHTTP Exit Node and Request counter for such
/// pHTTP Exit node and then encrypts and authenticates the data.
/// Called by the uHTTP client
/// Takes enveloped request data, the public key of the uHTTP Exit Node and Request counter for such
/// uHTTP Exit node and then encrypts and authenticates the data.
/// The encrypted data and new counter value to be persisted is returned in the resulting session.
export function boxRequest(
{
Expand Down Expand Up @@ -178,7 +178,7 @@ export function boxRequest(
}

const counterBuf = bigintToUint8BE(newCounter);
const versionBuf = new Uint8Array([pHTTP_CRYPTO_VERSION]);
const versionBuf = new Uint8Array([uHTTP_CRYPTO_VERSION]);

// V,W,C,R,T
const result = new Uint8Array(
Expand All @@ -199,9 +199,9 @@ export function boxRequest(
};
}

/// Called by the pHTTP Exit Node
/// Takes enveloped encrypted data, the private key of the pHTTP Exit Node and Request counter for
/// pHTTP Client node associated with the request and then decrypts and verifies the data.
/// Called by the uHTTP Exit Node
/// Takes enveloped encrypted data, the private key of the uHTTP Exit Node and Request counter for
/// uHTTP Client node associated with the request and then decrypts and verifies the data.
/// The decrypted data and new counter value to be persisted is returned in the resulting session.
/// Returns error and session if count verifcation failed so a response with the error message can still be boxed.
export function unboxRequest({
Expand All @@ -215,7 +215,7 @@ export function unboxRequest({
exitPeerId: string;
exitPrivateKey: Uint8Array;
}): Result {
if ((message[0] & 0x10) != (pHTTP_CRYPTO_VERSION & 0x10)) {
if ((message[0] & 0x10) != (uHTTP_CRYPTO_VERSION & 0x10)) {
return {
res: ResState.Failed,
error: 'unsupported protocol version',
Expand Down Expand Up @@ -285,9 +285,9 @@ export function unboxRequest({
};
}

/// Called by the pHTTP Exit Node
/// Called by the uHTTP Exit Node
/// Takes enveloped response data, the request session obtained by unboxRequest and Response counter for the associated
/// pHTTP Client node and then encrypts and authenticates the data.
/// uHTTP Client node and then encrypts and authenticates the data.
/// The encrypted data and new counter value to be persisted is returned in the resulting session.
export function boxResponse(
session: Session,
Expand Down Expand Up @@ -338,9 +338,9 @@ export function boxResponse(
};
}

/// Called by the pHTTP Client Node
/// Called by the uHTTP Client Node
/// Takes enveloped encrypted data, the associated session returned by boxRequest and Request counter for
/// pHTTP Exit node associated with the response and then decrypts and verifies the data.
/// uHTTP Exit node associated with the response and then decrypts and verifies the data.
/// The decrypted data and new counter value to be persisted is returned in the resulting session.
export function unboxResponse(
session: Session,
Expand Down
Loading
Loading