@sphereon/gx-compliance-client
Version:
<!--suppress HtmlDeprecatedAttribute --> <h1 align="center"> <br> <a href="https://www.sphereon.com"><img src="https://sphereon.com/content/themes/sphereon/assets/img/logo.svg" alt="Sphereon" width="400"></a> <br>Gaia-X Compliance client (Typescript
128 lines (127 loc) • 5.84 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.GXJsonWebSignature2020 = void 0;
const ld_suites_1 = require("@sphereon/ssi-sdk-vc-handler-ld-local/dist/ld-suites");
const u8a = __importStar(require("uint8arrays"));
const utils_1 = require("@veramo/utils");
const JsonWebKeyWithRSASupport_1 = require("./gx-impl/JsonWebKeyWithRSASupport");
const JsonWebSignatureWithRSASupport_1 = require("./gx-impl/JsonWebSignatureWithRSASupport");
/**
* WARNING:
*
* This suite is made specifically to be interoperable with Gaia-X. Do not use this suite for other purposes, as the current Gaia-X implementation contains multiple errors and does not conform to JsonWebSignature2020.
* If you do need regular JsonWebSignature2020 support, please configure the SphereonWebSignature2020 class when setting up the agent
*/
class GXJsonWebSignature2020 extends ld_suites_1.SphereonLdSignature {
getSupportedVerificationType() {
return 'JsonWebKey2020';
}
getSupportedVeramoKeyType() {
return 'RSA';
}
getSuiteForSigning(key, issuerDid, verificationMethodId, context) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const controller = issuerDid;
// DID Key ID
let id = verificationMethodId;
const alg = 'RS256';
const signer = {
// returns a JWS detached
sign: (args) => __awaiter(this, void 0, void 0, function* () {
const header = {
alg,
b64: false,
crit: ['b64'],
};
const headerString = (0, utils_1.encodeJoseBlob)(header);
const dataBuffer = u8a.fromString(args.data, 'utf-8');
const messageBuffer = u8a.concat([u8a.fromString(`${headerString}.`, 'utf-8'), dataBuffer]);
const messageString = u8a.toString(messageBuffer, 'base64'); //will be decoded to bytes in the keyManagerSign, hence the base64 arg to the method below
const signature = yield context.agent.keyManagerSign({
keyRef: key.kid,
algorithm: alg,
data: messageString,
encoding: 'base64',
}); // returns base64url signature
return `${headerString}..${signature}`;
}),
};
const publicKeyJwk = ((_a = key.meta) === null || _a === void 0 ? void 0 : _a.publicKeyJwk)
? key.meta.publicKeyJwk
: {
kty: 'OKP',
crv: 'Ed25519',
x: u8a.toString(u8a.fromString(key.publicKeyHex, 'hex'), 'base64url'),
};
const verificationKey = yield JsonWebKeyWithRSASupport_1.JsonWebKey.from({
id: id,
type: this.getSupportedVerificationType(),
controller: controller,
publicKeyJwk,
}, { signer, verifier: false });
// verificationKey.signer = () => signer
const suite = new JsonWebSignatureWithRSASupport_1.JsonWebSignature({
key: verificationKey,
});
return suite;
});
}
getSuiteForVerification() {
const verifier = {
// returns a JWS detached
verify: (args) => __awaiter(this, void 0, void 0, function* () {
return true;
}),
};
return new JsonWebSignatureWithRSASupport_1.JsonWebSignature({ verifier });
}
preSigningCredModification(credential) {
// do nothing
}
preSigningPresModification(presentation) {
// do nothing
}
preDidResolutionModification(didUrl, didDoc) {
// do nothing
}
getContext() {
return 'https://w3id.org/security/suites/jws-2020/v1';
}
preVerificationCredModification(credential) {
// do nothing
}
}
exports.GXJsonWebSignature2020 = GXJsonWebSignature2020;