Adding back all of our various SDK flavors. Need to figure out how to set up the android environment for build variants.
This commit is contained in:
Родитель
cdf5642327
Коммит
da6ae15f1e
Двоичный файл не отображается.
|
@ -68,4 +68,7 @@ typings/
|
|||
dist
|
||||
|
||||
# nunit test results
|
||||
nunitresults.xml
|
||||
nunitresults.xml
|
||||
|
||||
# macOS metadata files
|
||||
.DS_Store
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
.gradle/*
|
||||
.idea/*
|
||||
build/*
|
||||
build/*
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
plugins {
|
||||
id("org.jetbrains.kotlin.multiplatform") version '1.3.40'
|
||||
}
|
||||
|
@ -11,23 +12,23 @@ repositories {
|
|||
}
|
||||
}
|
||||
|
||||
group 'com.microsoft'
|
||||
group 'com.microsoft.did.sdk'
|
||||
version '0.0.1'
|
||||
|
||||
kotlin {
|
||||
jvm()
|
||||
iosArm64()
|
||||
// js {
|
||||
// browser {
|
||||
// }
|
||||
// nodejs {
|
||||
// }
|
||||
// }
|
||||
iosArm64("ios")
|
||||
js {
|
||||
browser {
|
||||
}
|
||||
nodejs {
|
||||
}
|
||||
}
|
||||
// For ARM, should be changed to iosArm32 or iosArm64
|
||||
// For Linux, should be changed to e.g. linuxX64
|
||||
// For MacOS, should be changed to e.g. macosX64
|
||||
// For Windows, should be changed to e.g. mingwX64
|
||||
// macosX64("macos")
|
||||
macosX64("macos")
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
|
@ -52,20 +53,21 @@ kotlin {
|
|||
implementation kotlin('test-junit')
|
||||
}
|
||||
}
|
||||
// jsMain {
|
||||
// dependencies {
|
||||
// implementation kotlin('stdlib-js')
|
||||
// }
|
||||
// }
|
||||
// jsTest {
|
||||
// dependencies {
|
||||
// implementation kotlin('test-js')
|
||||
// }
|
||||
// }
|
||||
// macosMain {
|
||||
// }
|
||||
// macosTest {
|
||||
// }
|
||||
android
|
||||
jsMain {
|
||||
dependencies {
|
||||
implementation kotlin('stdlib-js')
|
||||
}
|
||||
}
|
||||
jsTest {
|
||||
dependencies {
|
||||
implementation kotlin('test-js')
|
||||
}
|
||||
}
|
||||
macosMain {
|
||||
}
|
||||
macosTest {
|
||||
}
|
||||
iosMain {
|
||||
}
|
||||
iosTest {
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
/Users/logirvin/Documents/secp256k1/build/libs/org.bitcoin.jar
|
|
@ -1,11 +0,0 @@
|
|||
package com.microsoft.useragentSdk
|
||||
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class SampleTestsJS {
|
||||
@Test
|
||||
fun testHello() {
|
||||
assertTrue("JS" in hello())
|
||||
}
|
||||
}
|
|
@ -3,9 +3,34 @@ package com.microsoft.useragentSdk.crypto
|
|||
import com.microsoft.useragentSdk.crypto.models.webCryptoApi.*
|
||||
import com.microsoft.useragentSdk.crypto.plugins.subtleCrypto.Provider
|
||||
import org.bitcoin.NativeSecp256k1
|
||||
import java.io.File
|
||||
import java.security.SecureRandom
|
||||
|
||||
class Secp256k1Provider(): Provider() {
|
||||
companion object {
|
||||
init {
|
||||
val libraryStream = Secp256k1Provider::class.java.getResourceAsStream("libsecp256k1.so")
|
||||
val library = File.createTempFile("libsecp256k1", ".so")
|
||||
|
||||
val bufferSize = 256
|
||||
var buffer = ByteArray(bufferSize)
|
||||
var validBytes = libraryStream.read(buffer)
|
||||
var offset = 0
|
||||
while (validBytes > 0) {
|
||||
if (validBytes < bufferSize) {
|
||||
library.writeBytes(buffer.slice( 0 until validBytes).toByteArray())
|
||||
} else {
|
||||
library.writeBytes(buffer)
|
||||
}
|
||||
offset += validBytes
|
||||
validBytes = libraryStream.read(buffer, offset, bufferSize)
|
||||
}
|
||||
|
||||
System.load(library.absolutePath);
|
||||
library.delete()
|
||||
}
|
||||
}
|
||||
|
||||
override val name: String = "ECDSA"
|
||||
override val privateKeyUsage: Set<KeyUsage> = setOf(KeyUsage.Sign)
|
||||
override val publicKeyUsage: Set<KeyUsage> = setOf(KeyUsage.Verify)
|
||||
|
@ -16,11 +41,6 @@ class Secp256k1Provider(): Provider() {
|
|||
extractable: Boolean,
|
||||
keyUsages: Set<KeyUsage>
|
||||
): CryptoKeyPair {
|
||||
val keyGenParams = algorithm as? EcKeyGenParams ?: throw Error("EcKeyGenParams expected as algorithm")
|
||||
if (keyGenParams.namedCurve.toUpperCase() != W3cCryptoApiConstants.Secp256k1.value.toUpperCase() &&
|
||||
keyGenParams.namedCurve.toUpperCase() != W3cCryptoApiConstants.Secp256k1.name.toUpperCase()) {
|
||||
throw Error("The curve ${keyGenParams.namedCurve} is not supported by Secp256k1Provider")
|
||||
}
|
||||
val seed = ByteArray(32)
|
||||
val random = SecureRandom()
|
||||
random.nextBytes(seed)
|
||||
|
@ -47,4 +67,12 @@ class Secp256k1Provider(): Provider() {
|
|||
|
||||
return return keyPair
|
||||
}
|
||||
|
||||
override fun checkGenerateKeyParams(algorithm: Algorithm) {
|
||||
val keyGenParams = algorithm as? EcKeyGenParams ?: throw Error("EcKeyGenParams expected as algorithm")
|
||||
if (keyGenParams.namedCurve.toUpperCase() != W3cCryptoApiConstants.Secp256k1.value.toUpperCase() &&
|
||||
keyGenParams.namedCurve.toUpperCase() != W3cCryptoApiConstants.Secp256k1.name.toUpperCase()) {
|
||||
throw Error("The curve ${keyGenParams.namedCurve} is not supported by Secp256k1Provider")
|
||||
}
|
||||
}
|
||||
}
|
Двоичный файл не отображается.
|
@ -0,0 +1,11 @@
|
|||
package com.microsoft.useragentSdk.crypto
|
||||
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class EllipticCurveSubtleCryptoTests {
|
||||
@Test
|
||||
fun testHello() {
|
||||
assertTrue(true)
|
||||
}
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
package com.microsoft.useragentSdk
|
||||
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class SampleTestsNative {
|
||||
@Test
|
||||
fun testHello() {
|
||||
assertTrue("Native" in hello())
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче