-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
179 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import express from "express"; | ||
import asyncHandler from "express-async-handler"; | ||
|
||
export const createServer = (rp) => { | ||
|
||
const app = express(); | ||
app.use(express.json()); | ||
app.route("/api/health").get( | ||
asyncHandler(async (req, res) => { | ||
res.status(200).send(); | ||
}) | ||
); | ||
app.route("/api/auth").post( | ||
asyncHandler(async (req, res) => { | ||
console.log(req); | ||
await rp.verifyAuthResponse(req.body); | ||
res.status(204).send(); | ||
}) | ||
); | ||
|
||
const port = 3333; | ||
const server = app.listen(port, "0.0.0.0", () => { | ||
console.log(`HTTP server listening on port ${port}`); | ||
}); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { | ||
RelyingParty, | ||
SigningAlgs, | ||
bytesToString, | ||
} from "@tanglelabs/oid4vc"; | ||
import * as KeyDIDResolver from "key-did-resolver"; | ||
import { Resolver } from "did-resolver"; | ||
|
||
//@ts-ignore | ||
import { driver } from "@digitalbazaar/did-method-key"; | ||
//@ts-ignore | ||
import { Ed25519VerificationKey2020 } from "@digitalbazaar/ed25519-verification-key-2020"; | ||
|
||
|
||
import { remoteSigner } from "./remoteSigner"; | ||
import { createService } from "./grpcService"; | ||
import { createServer } from "./httpServer"; | ||
|
||
(async () => { | ||
|
||
const didKeyDriver = driver(); | ||
|
||
didKeyDriver.use({ | ||
multibaseMultikeyHeader: "z6Mk", | ||
fromMultibase: Ed25519VerificationKey2020.from, | ||
}); | ||
|
||
const verificationKeyPair = await Ed25519VerificationKey2020.generate(); | ||
|
||
console.log(bytesToString(verificationKeyPair._publicKeyBuffer)); | ||
console.log(bytesToString(verificationKeyPair._privateKeyBuffer)); | ||
|
||
const keyDidResolver = KeyDIDResolver.getResolver(); | ||
let resolver = new Resolver(keyDidResolver); | ||
|
||
const rp = new RelyingParty({ | ||
clientId: "did:iota:0x", | ||
clientMetadata: { | ||
subjectSyntaxTypesSupported: [ | ||
"did:iota" | ||
], | ||
idTokenSigningAlgValuesSupported: [ | ||
SigningAlgs.EdDSA | ||
], | ||
}, | ||
did: "did:iota:0x", | ||
kid: "did:iota:0x#my_key", | ||
signer: remoteSigner(process.env.SIGNER_KEYID), | ||
redirectUri: "http://192.168.0.234:8080/api/auth", | ||
resolver: resolver, | ||
}); | ||
|
||
createService(rp); | ||
createServer(rp); | ||
|
||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import path from "path"; | ||
import { fileURLToPath } from 'url'; | ||
import { dirname } from 'path'; | ||
import * as grpc from "@grpc/grpc-js"; | ||
import { loadSync } from "@grpc/proto-loader"; | ||
import { Signer } from 'did-jwt'; | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = dirname(__filename); | ||
|
||
const identityProtoPath = path.join( | ||
__dirname, | ||
"..", | ||
"..", | ||
"..", | ||
"proto/identity/utils.proto" | ||
); | ||
|
||
const identityPackageDefinition = loadSync(identityProtoPath); | ||
const identityPackage = grpc.loadPackageDefinition(identityPackageDefinition).utils; | ||
|
||
export const remoteSigner: (keyId: string) => Signer = (keyId) => async (data) => { | ||
|
||
//@ts-ignore | ||
const identityClient = new identityPackage.Signing( | ||
'identity:50051', grpc.credentials.createInsecure() | ||
); | ||
|
||
console.debug(data); | ||
|
||
const response = await new Promise((resolve, reject) => identityClient.sign({ | ||
keyId, | ||
data: Array.from(Buffer.from(data)), | ||
}, (err, response) => { | ||
if (err) { | ||
console.error(err); | ||
} | ||
resolve(response); | ||
})); | ||
console.log(response) | ||
return response as string; | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Copyright 2020-2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
syntax = "proto3"; | ||
package utils; | ||
|
||
message DataSigningRequest { | ||
// Raw data that will be signed. | ||
bytes data = 1; | ||
// Signing key's ID. | ||
string key_id = 2; | ||
} | ||
|
||
message DataSigningResponse { | ||
// Raw data signature. | ||
bytes signature = 1; | ||
} | ||
|
||
// Service that handles signing operations on raw data. | ||
service Signing { | ||
rpc sign(DataSigningRequest) returns (DataSigningResponse); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters