-
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.
feat(BAE): updating jsMain Ed25519 keys for use in TS (#92)
Co-authored-by: Ahmed Moussa <[email protected]> Signed-off-by: Curtis <[email protected]>
- Loading branch information
Showing
12 changed files
with
262 additions
and
15 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
...mmetric-encryption/src/commonMain/kotlin/io/iohk/atala/prism/apollo/utils/KMMEdKeyPair.kt
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
3 changes: 3 additions & 0 deletions
3
...ric-encryption/src/commonMain/kotlin/io/iohk/atala/prism/apollo/utils/KMMX25519KeyPair.kt
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
31 changes: 31 additions & 0 deletions
31
...mmetric-encryption/src/jsMain/kotlin/io/iohk/atala/prism/apollo/utils/Curve25519Parser.kt
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,31 @@ | ||
package io.iohk.atala.prism.apollo.utils | ||
|
||
import io.iohk.atala.prism.apollo.base64.base64UrlDecodedBytes | ||
import node.buffer.Buffer | ||
|
||
@ExperimentalJsExport | ||
@JsExport | ||
object Curve25519Parser { | ||
val encodedLength = 43 | ||
val rawLength = 32 | ||
|
||
/** | ||
* Resolve the given ByteArray into the raw key value | ||
* @param bytes - ByteArray to be parsed, either Encoded or Raw data | ||
* @throws Error - if [bytes] is neither Encoded nor Raw | ||
* @return Buffer - raw key value | ||
*/ | ||
fun parseRaw(bytes: ByteArray): Buffer { | ||
val buffer = Buffer.from(bytes) | ||
|
||
if (buffer.length == encodedLength) { | ||
return Buffer.from(buffer.toByteArray().decodeToString().base64UrlDecodedBytes) | ||
} | ||
|
||
if (buffer.length == rawLength) { | ||
return buffer | ||
} | ||
|
||
throw Error("invalid raw key") | ||
} | ||
} |
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
26 changes: 25 additions & 1 deletion
26
...ymmetric-encryption/src/jsMain/kotlin/io/iohk/atala/prism/apollo/utils/KMMEdPrivateKey.kt
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
27 changes: 25 additions & 2 deletions
27
...symmetric-encryption/src/jsMain/kotlin/io/iohk/atala/prism/apollo/utils/KMMEdPublicKey.kt
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
35 changes: 34 additions & 1 deletion
35
...tric-encryption/src/jsMain/kotlin/io/iohk/atala/prism/apollo/utils/KMMX25519PrivateKey.kt
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 |
---|---|---|
@@ -1,5 +1,38 @@ | ||
package io.iohk.atala.prism.apollo.utils | ||
|
||
import io.iohk.atala.prism.apollo.base64.base64UrlEncoded | ||
import io.iohk.atala.prism.apollo.utils.external.KeyPair | ||
import io.iohk.atala.prism.apollo.utils.external.generateKeyPairFromSeed | ||
import node.buffer.Buffer | ||
|
||
@ExperimentalJsExport | ||
@JsExport | ||
actual class KMMX25519PrivateKey(val raw: ByteArray) | ||
actual class KMMX25519PrivateKey(bytes: ByteArray) { | ||
val raw: Buffer | ||
|
||
init { | ||
raw = Curve25519Parser.parseRaw(bytes) | ||
} | ||
|
||
/** | ||
* Base64 url encodes the raw value | ||
* @return Buffer | ||
*/ | ||
fun getEncoded(): Buffer { | ||
return Buffer.from(raw.toByteArray().base64UrlEncoded) | ||
} | ||
|
||
/** | ||
* PublicKey associated with this PrivateKey | ||
* @return KMMX25519PublicKey | ||
*/ | ||
fun publicKey(): KMMX25519PublicKey { | ||
val publicBytes = getInstance().publicKey.buffer.toByteArray() | ||
|
||
return KMMX25519PublicKey(publicBytes) | ||
} | ||
|
||
private fun getInstance(): KeyPair { | ||
return generateKeyPairFromSeed(raw) | ||
} | ||
} |
19 changes: 18 additions & 1 deletion
19
...etric-encryption/src/jsMain/kotlin/io/iohk/atala/prism/apollo/utils/KMMX25519PublicKey.kt
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 |
---|---|---|
@@ -1,5 +1,22 @@ | ||
package io.iohk.atala.prism.apollo.utils | ||
|
||
import io.iohk.atala.prism.apollo.base64.base64UrlEncoded | ||
import node.buffer.Buffer | ||
|
||
@ExperimentalJsExport | ||
@JsExport | ||
actual class KMMX25519PublicKey(val raw: ByteArray) | ||
actual class KMMX25519PublicKey(bytes: ByteArray) { | ||
val raw: Buffer | ||
|
||
init { | ||
raw = Curve25519Parser.parseRaw(bytes) | ||
} | ||
|
||
/** | ||
* Base64 url encodes the raw value | ||
* @return Buffer | ||
*/ | ||
fun getEncoded(): Buffer { | ||
return Buffer.from(raw.toByteArray().base64UrlEncoded.encodeToByteArray()) | ||
} | ||
} |
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
Oops, something went wrong.