Skip to content

Commit

Permalink
Merge branch 'TBD54566975:main' into didweb
Browse files Browse the repository at this point in the history
  • Loading branch information
aazam-gh authored Oct 9, 2024
2 parents 30bad31 + d4bf728 commit 1246f86
Show file tree
Hide file tree
Showing 22 changed files with 1,017 additions and 9 deletions.
83 changes: 83 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<!--
For Work In Progress Pull Requests, please use the Draft PR feature,
see https://github.blog/2019-02-14-introducing-draft-pull-requests/ for further details.
For a timely review/response, please avoid force-pushing additional
commits if your PR already received reviews or comments.
Before submitting a Pull Request, please ensure you've done the following:
- 📖 Read the TBD Developer Website Contributing Guide: https://github.com/TBD54566975/developer.tbd.website/blob/main/CONTRIBUTING.md.
- 📖 Read the TBD Developer Website Code of Conduct: https://github.com/TBD54566975/developer.tbd.website/blob/main/CODE_OF_CONDUCT.md.
- 👷‍♀️ Create small PRs. In most cases, this will be possible.
- ✅ Provide tests for your changes.
- 📝 Use descriptive commit messages.
- 📗 Update any related documentation and include any relevant screenshots.
-->

## What type of PR is this? (check all applicable)

- [ ] ♻️ Refactor
- [ ] ✨ New Feature
- [ ] 🐛 Bug Fix
- [ ] 📝 Documentation Update
- [ ] 👷 Example Application
- [ ] 🧑‍💻 Code Snippet
- [ ] 🎨 Design
- [ ] 📖 Content
- [ ] 🧪 Tests
- [ ] 🔖 Release
- [ ] 🚩 Other

## Description

<!-- Please do not leave this blank -->

This PR [adds/removes/fixes/replaces] this [feature/bug/etc].

## Related Tickets & Documents
<!--
Please use this format link issue numbers: Resolves #123
https://docs.github.com/en/free-pro-team@latest/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword
-->
Resolves #

## Mobile & Desktop Screenshots/Recordings

<!-- Visual changes require screenshots -->

## Added code snippets?
- [ ] 👍 yes
- [ ] 🙅 no, because they aren't needed

## Added tests?

- [ ] 👍 yes
- [ ] 🙅 no, because they aren't needed
- [ ] 🙋 no, because I need help

### No tests? Add a note
<!--
If you didn't provide tests with this PR, please explain here why they aren't needed.
-->

## Added to documentation?

- [ ] 📜 readme
- [ ] 📜 contributing.md
- [ ] 📓 general documentation
- [ ] 🙅 no documentation needed

### No docs? Add a note
<!--
If you didn't provide documentation with this PR, please explain here why it's not needed.
-->

## [optional] Are there any post-deployment tasks we need to perform?



## [optional] What gif best describes this PR or how it makes you feel?



<!-- note: PRs with deletes sections will be marked invalid -->
79 changes: 79 additions & 0 deletions .github/workflows/add-hacktoberfest-labels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Propagate Issue Labels to PR
on:
pull_request:
types: [opened, synchronize]
jobs:
copy_labels:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get issue number from PR body
id: issue_number
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const prBody = context.payload.pull_request.body || '';
// Remove HTML comments
const bodyWithoutComments = prBody.replace(/<!--[\s\S]*?-->/g, '');
// Find issue number
const match = bodyWithoutComments.match(/(?:Resolves|Closes) #(\d+)/);
const issueNumber = match ? match[1] : null;
if (issueNumber) {
console.log(`Issue number found: ${issueNumber}`);
core.setOutput('has_issue', 'true');
core.setOutput('issue_number', issueNumber);
} else {
console.log('No issue number found in PR body');
core.setOutput('has_issue', 'false');
}
- name: Get labels from linked issue
if: steps.issue_number.outputs.has_issue == 'true'
uses: actions/github-script@v6
id: issue_labels
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issue_number = ${{ steps.issue_number.outputs.issue_number }};
try {
const issue = await github.rest.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: parseInt(issue_number)
});
return issue.data.labels.map(label => label.name);
} catch (error) {
console.log(`Error fetching issue labels: ${error}`);
return [];
}
- name: Check for required labels
if: steps.issue_number.outputs.has_issue == 'true' && steps.issue_labels.outputs.result != '[]'
id: check_labels
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const labels = ${{ steps.issue_labels.outputs.result }};
const hacktoberfestLabel = labels.some(label => label.toLowerCase().includes('hacktoberfest'));
const sizeLabelPresent = labels.some(label => ['small', 'medium', 'large'].includes(label.toLowerCase()));
return hacktoberfestLabel || sizeLabelPresent;
- name: Add labels to PR
if: steps.issue_number.outputs.has_issue == 'true' && steps.check_labels.outputs.result == 'true'
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const pr_number = context.issue.number;
const labels = ${{ steps.issue_labels.outputs.result }};
try {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr_number,
labels: labels
});
console.log('Labels added successfully');
} catch (error) {
console.log(`Error adding labels: ${error}`);
}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ bound/LICENSE
bound/typescript/dist/*
!bound/typescript/dist/index.js
bound/typescript/tests/compiled
bound/typescript/src/wasm/generated.js
bound/typescript/src/wasm/generated.js

# macOS
.DS_Store
5 changes: 3 additions & 2 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ setup:
if [ ! -d ".git/modules/web5-spec" ]; then
git submodule update --init --recursive
fi
if [[ "$(cargo 2>&1)" == *"rustup could not choose a version of cargo to run"* ]]; then
rustup default 1.76.0 # TODO undo this
if [[ "$(cargo --version)" != "cargo 1.76.0"* ]]; then
rustup install 1.76.0
rustup default 1.76.0
rustup target add aarch64-apple-darwin
fi
if ! command -v wasm-pack >/dev/null || [[ "$(wasm-pack --version)" != "wasm-pack 0.13.0" ]]; then
Expand Down
1 change: 0 additions & 1 deletion bindings/web5_wasm/src/crypto/dsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use web5::crypto::dsa::{
secp256k1::{Secp256k1Generator, Secp256k1Signer},
Signer,
};

#[wasm_bindgen]
pub struct WasmSigner {
inner: Arc<dyn Signer>,
Expand Down
12 changes: 12 additions & 0 deletions bindings/web5_wasm/src/crypto/key_managers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ impl From<InMemoryKeyManager> for WasmKeyManager {
}
}

impl From<Arc<dyn KeyManager>> for WasmKeyManager {
fn from(value: Arc<dyn KeyManager>) -> Self {
Self { inner: value }
}
}

impl From<WasmKeyManager> for Arc<dyn KeyManager> {
fn from(wasm_key_manager: WasmKeyManager) -> Self {
wasm_key_manager.inner
}
}

#[wasm_bindgen]
impl WasmKeyManager {
pub fn import_private_jwk(&self, private_jwk: WasmJwk) -> Result<WasmJwk> {
Expand Down
66 changes: 66 additions & 0 deletions bindings/web5_wasm/src/dids/bearer_did.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
use crate::errors::{map_err, Result};
use wasm_bindgen::prelude::wasm_bindgen;
use web5::dids::bearer_did::BearerDid;
use crate::crypto::dsa::WasmSigner;
use crate::crypto::key_managers::WasmKeyManager;
use crate::dids::did::WasmDid;
use crate::dids::document::WasmDocument;
use crate::dids::portable_did::WasmPortableDid;

#[wasm_bindgen]
pub struct WasmBearerDid {
inner: BearerDid,
}

impl From<WasmBearerDid> for BearerDid {
fn from(value: WasmBearerDid) -> Self {
value.inner
}
}

#[wasm_bindgen]
impl WasmBearerDid {
#[wasm_bindgen(constructor)]
pub fn new(did: WasmDid, document: WasmDocument, key_manager: WasmKeyManager) -> Self {
Self {
inner: BearerDid {
did: did.into(),
document: document.into(),
key_manager: key_manager.into(),
},
}
}

#[wasm_bindgen]
pub fn from_portable_did(portable_did: WasmPortableDid) -> Result<WasmBearerDid> {
Ok(Self {
inner: BearerDid::from_portable_did(portable_did.into()).map_err(map_err)?,
})
}

// todo key exporter for to_portable_did

#[wasm_bindgen]
pub fn get_signer(&self, verification_method_id: &str) -> Result<WasmSigner> {
Ok(self
.inner
.get_signer(verification_method_id)
.map_err(map_err)?
.into())
}

#[wasm_bindgen(getter)]
pub fn did(&self) -> WasmDid {
self.inner.did.clone().into()
}

#[wasm_bindgen(getter)]
pub fn document(&self) -> WasmDocument {
self.inner.document.clone().into()
}

#[wasm_bindgen(getter)]
pub fn key_manager(&self) -> WasmKeyManager {
self.inner.key_manager.clone().into()
}
}
99 changes: 99 additions & 0 deletions bindings/web5_wasm/src/dids/did.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
use std::collections::HashMap;
use wasm_bindgen::prelude::wasm_bindgen;
use wasm_bindgen::JsValue;
use web5::dids::did::Did;

#[wasm_bindgen]
pub struct WasmDid {
inner: Did,
}

impl From<WasmDid> for Did {
fn from(value: WasmDid) -> Self {
value.inner
}
}

impl From<Did> for WasmDid {
fn from(value: Did) -> Self {
WasmDid { inner: value }
}
}

#[wasm_bindgen]
impl WasmDid {
#[allow(clippy::too_many_arguments)]
#[wasm_bindgen(constructor)]
pub fn new(
uri: String,
url: String,
method: String,
id: String,
params: JsValue,
path: Option<String>,
query: Option<String>,
fragment: Option<String>,
) -> Self {
let params = if params.is_undefined() {
None
} else {
serde_wasm_bindgen::from_value(params).unwrap_or(Some(HashMap::new()))
};

Self {
inner: Did {
uri,
url,
method,
id,
params,
path,
query,
fragment,
},
}
}

#[wasm_bindgen(getter)]
pub fn uri(&self) -> String {
self.inner.uri.clone()
}

#[wasm_bindgen(getter)]
pub fn url(&self) -> String {
self.inner.url.clone()
}

#[wasm_bindgen(getter)]
pub fn method(&self) -> String {
self.inner.method.clone()
}

#[wasm_bindgen(getter)]
pub fn id(&self) -> String {
self.inner.id.clone()
}

#[wasm_bindgen(getter)]
pub fn params(&self) -> JsValue {
match &self.inner.params {
Some(map) => serde_wasm_bindgen::to_value(map).unwrap_or(JsValue::undefined()),
None => JsValue::undefined(),
}
}

#[wasm_bindgen(getter)]
pub fn path(&self) -> Option<String> {
self.inner.path.clone()
}

#[wasm_bindgen(getter)]
pub fn query(&self) -> Option<String> {
self.inner.query.clone()
}

#[wasm_bindgen(getter)]
pub fn fragment(&self) -> Option<String> {
self.inner.fragment.clone()
}
}
Loading

0 comments on commit 1246f86

Please sign in to comment.