Skip to content

Commit

Permalink
chore: use identus apollo (#247)
Browse files Browse the repository at this point in the history
Signed-off-by: Curtish <ch@curtish.me>
  • Loading branch information
curtis-h authored Jul 15, 2024
1 parent 0a32269 commit 2afbbc1
Show file tree
Hide file tree
Showing 15 changed files with 138 additions and 122 deletions.
106 changes: 61 additions & 45 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
"outputName": "junit.xml"
},
"dependencies": {
"@atala/apollo": "^1.3.5",
"@hyperledger/identus-apollo": "^1.3.6",
"@scure/bip32": "^1.3.0",
"@scure/bip39": "^1.1.1",
"@sd-jwt/sd-jwt-vc": "^0.7.1",
Expand Down
20 changes: 10 additions & 10 deletions src/apollo/Apollo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { Ed25519PublicKey } from "./utils/Ed25519PublicKey";
import { X25519PublicKey } from "./utils/X25519PublicKey";

import { notEmptyString } from "../utils";
import ApolloPKG from "@atala/apollo";
import ApolloPKG from "@hyperledger/identus-apollo";
import { PrismDerivationPath } from "../domain/models/derivation/schemas/PrismDerivation";

const ApolloSDK = ApolloPKG.org.hyperledger.identus.apollo;
Expand Down Expand Up @@ -238,7 +238,7 @@ export default class Apollo implements ApolloInterface, KeyRestoration {
if (keyData) {
return new Ed25519PublicKey(keyData);
}
throw new ApolloError.InvalidPrivateKey("Missing raw bytes")
throw new ApolloError.InvalidPrivateKey("Missing raw bytes");
}
if (curve === Curve.SECP256K1) {
if (keyData) {
Expand All @@ -250,10 +250,10 @@ export default class Apollo implements ApolloInterface, KeyRestoration {
return Secp256k1PublicKey.secp256k1FromByteCoordinates(
xData,
yData
)
);
}
}
throw new ApolloError.InvalidPrivateKey("Missing raw bytes or coordinates")
throw new ApolloError.InvalidPrivateKey("Missing raw bytes or coordinates");
}
}

Expand All @@ -262,7 +262,7 @@ export default class Apollo implements ApolloInterface, KeyRestoration {
if (keyData) {
return new X25519PublicKey(keyData);
}
throw new ApolloError.InvalidPrivateKey("Missing raw bytes")
throw new ApolloError.InvalidPrivateKey("Missing raw bytes");
}
}

Expand Down Expand Up @@ -358,14 +358,14 @@ export default class Apollo implements ApolloInterface, KeyRestoration {
if (notEmptyString(seedHex)) {

const derivationIndex = parameters[KeyProperties.index] ?? "0";
const derivationParam = parameters[KeyProperties.derivationPath]
const defaultPath: string = derivationParam ?? PrismDerivationPath.init(derivationIndex).toString()
const derivationParam = parameters[KeyProperties.derivationPath];
const defaultPath: string = derivationParam ?? PrismDerivationPath.init(derivationIndex).toString();


const seed = Int8Array.from(Buffer.from(seedHex, "hex"));

const hdKey = ApolloSDK.derivation.EdHDKey.Companion.initFromSeed(seed);
const baseKey = new Ed25519PrivateKey(Uint8Array.from(hdKey.privateKey))
const baseKey = new Ed25519PrivateKey(Uint8Array.from(hdKey.privateKey));

baseKey.keySpecification.set(KeyProperties.chainCode, Buffer.from(Uint8Array.from(hdKey.chainCode)).toString("hex"));
baseKey.keySpecification.set(KeyProperties.derivationPath, Buffer.from(defaultPath).toString("hex"));
Expand All @@ -390,15 +390,15 @@ export default class Apollo implements ApolloInterface, KeyRestoration {

const seedHex = parameters[KeyProperties.seed];
if (!seedHex) {
throw new ApolloError.MissingKeyParameters(["seed"])
throw new ApolloError.MissingKeyParameters(["seed"]);
}
const seed = Buffer.from(seedHex, "hex");

const derivationIndex = parameters[KeyProperties.index] ?? "0";
const derivationParam = parameters[KeyProperties.derivationPath];
const defaultPath: string = derivationParam ?? PrismDerivationPath.init(
derivationIndex
).toString()
).toString();

const hdKey = HDKey.InitFromSeed(
Int8Array.from(seed),
Expand Down
2 changes: 1 addition & 1 deletion src/apollo/utils/Ed25519KeyPair.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { KeyPair } from "../../domain";
import { Ed25519PrivateKey } from "./Ed25519PrivateKey";
import { Ed25519PublicKey } from "./Ed25519PublicKey";
import ApolloPKG from "@atala/apollo";
import ApolloPKG from "@hyperledger/identus-apollo";
const ApolloSDK = ApolloPKG.org.hyperledger.identus.apollo;

/**
Expand Down
10 changes: 5 additions & 5 deletions src/apollo/utils/Ed25519PrivateKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import {
ApolloError
} from "../../domain";

import ApolloPKG from "@atala/apollo";
import ApolloPKG from "@hyperledger/identus-apollo";
const ApolloSDK = ApolloPKG.org.hyperledger.identus.apollo;
const BigIntegerWrapper = ApolloSDK.derivation.BigIntegerWrapper;
const EdHDKey = ApolloSDK.derivation.EdHDKey
const EdHDKey = ApolloSDK.derivation.EdHDKey;
/**
* @ignore
*/
Expand Down Expand Up @@ -54,15 +54,15 @@ export class Ed25519PrivateKey extends PrivateKey implements DerivableKey, Expor
derivationPathStr.split("/").slice(1).length,
BigIntegerWrapper.initFromInt(0)
);
const derived = hdKey.derive(derivationPathStr)
const sk = new Ed25519PrivateKey(Uint8Array.from(derived.privateKey))
const derived = hdKey.derive(derivationPathStr);
const sk = new Ed25519PrivateKey(Uint8Array.from(derived.privateKey));
sk.keySpecification.set(KeyProperties.derivationPath, Buffer.from(derivationPathStr).toString("hex"));
sk.keySpecification.set(KeyProperties.index, `${this.index ?? 0}`);
if (derived.chainCode) {
sk.keySpecification.set(KeyProperties.chainCode, Buffer.from(derived.chainCode).toString("hex"));
}

return sk
return sk;
}

publicKey() {
Expand Down
2 changes: 1 addition & 1 deletion src/apollo/utils/Ed25519PublicKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
VerifiableKey
} from "../../domain";

import ApolloPKG from "@atala/apollo";
import ApolloPKG from "@hyperledger/identus-apollo";
const ApolloSDK = ApolloPKG.org.hyperledger.identus.apollo;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/apollo/utils/Secp256k1KeyPair.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { KeyPair, MnemonicWordList } from "../../domain";
import { Secp256k1PrivateKey } from "./Secp256k1PrivateKey";
import { Secp256k1PublicKey } from "./Secp256k1PublicKey";
import ApolloPKG from "@atala/apollo";
import ApolloPKG from "@hyperledger/identus-apollo";
const ApolloSDK = ApolloPKG.org.hyperledger.identus.apollo;

/**
Expand Down
4 changes: 2 additions & 2 deletions src/apollo/utils/Secp256k1PrivateKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
StorableKey,
} from "../../domain/models/keyManagement";

import ApolloPKG from "@atala/apollo";
import ApolloPKG from "@hyperledger/identus-apollo";
import { normaliseDER } from "../../domain/utils/DER";
const ApolloSDK = ApolloPKG.org.hyperledger.identus.apollo;
const HDKey = ApolloSDK.derivation.HDKey;
Expand Down Expand Up @@ -93,7 +93,7 @@ export class Secp256k1PrivateKey
}

sign(message: Buffer) {
const normalised = normaliseDER(Buffer.from(Uint8Array.from(this.native.sign(Int8Array.from(message)))))
const normalised = normaliseDER(Buffer.from(Uint8Array.from(this.native.sign(Int8Array.from(message)))));
return normalised;
}

Expand Down
2 changes: 1 addition & 1 deletion src/apollo/utils/Secp256k1PublicKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
VerifiableKey
} from "../../domain/models/keyManagement";

import ApolloPKG from "@atala/apollo";
import ApolloPKG from "@hyperledger/identus-apollo";
const ApolloSDK = ApolloPKG.org.hyperledger.identus.apollo;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/apollo/utils/X25519KeyPair.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { X25519PrivateKey } from "./X25519PrivateKey";
import { X25519PublicKey } from "./X25519PublicKey";
import { KeyPair } from "../../domain";
import ApolloPKG from "@atala/apollo";
import ApolloPKG from "@hyperledger/identus-apollo";
const ApolloSDK = ApolloPKG.org.hyperledger.identus.apollo;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/apollo/utils/X25519PrivateKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
StorableKey
} from "../../domain";

import ApolloPKG from "@atala/apollo";
import ApolloPKG from "@hyperledger/identus-apollo";
const ApolloSDK = ApolloPKG.org.hyperledger.identus.apollo;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/apollo/utils/X25519PublicKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
StorableKey
} from "../../domain";

import ApolloPKG from "@atala/apollo";
import ApolloPKG from "@hyperledger/identus-apollo";
const ApolloSDK = ApolloPKG.org.hyperledger.identus.apollo;

/**
Expand Down
Loading

1 comment on commit 2afbbc1

@github-actions
Copy link

Choose a reason for hiding this comment

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

Lines Statements Branches Functions
Coverage: 75%
75.37% (2788/3699) 65.03% (1356/2085) 80.55% (721/895)

JUnit

Tests Skipped Failures Errors Time
504 6 💤 0 ❌ 0 🔥 1m 19s ⏱️

Please sign in to comment.