@pagopa/io-react-native-iso18013 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/IoReactNativeIso18013.podspec +29 -0
- package/LICENSE +20 -0
- package/README.md +30 -0
- package/android/build.gradle +83 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/ioreactnativeiso18013/Base64Utils.kt +56 -0
- package/android/src/main/java/com/ioreactnativeiso18013/IoReactNativeCborModule.kt +209 -0
- package/android/src/main/java/com/ioreactnativeiso18013/IoReactNativeIso18013Module.kt +439 -0
- package/android/src/main/java/com/ioreactnativeiso18013/IoReactNativeIso18013Package.kt +17 -0
- package/ios/Base64Utils.swift +47 -0
- package/ios/IoReactNativeCbor.mm +32 -0
- package/ios/IoReactNativeCbor.swift +188 -0
- package/ios/IoReactNativeIso18013-Bridging-Header.h +2 -0
- package/ios/IoReactNativeIso18013.mm +43 -0
- package/ios/IoReactNativeIso18013.swift +491 -0
- package/lib/module/cbor/cbor/README.md +95 -0
- package/lib/module/cbor/cbor/decoder.js +51 -0
- package/lib/module/cbor/cbor/decoder.js.map +1 -0
- package/lib/module/cbor/cbor/failure.js +2 -0
- package/lib/module/cbor/cbor/failure.js.map +1 -0
- package/lib/module/cbor/cbor/index.js +5 -0
- package/lib/module/cbor/cbor/index.js.map +1 -0
- package/lib/module/cbor/cbor/schema.js +117 -0
- package/lib/module/cbor/cbor/schema.js.map +1 -0
- package/lib/module/cbor/cbor/schema.utils.js +16 -0
- package/lib/module/cbor/cbor/schema.utils.js.map +1 -0
- package/lib/module/cbor/cose/README.md +53 -0
- package/lib/module/cbor/cose/failure.js +2 -0
- package/lib/module/cbor/cose/failure.js.map +1 -0
- package/lib/module/cbor/cose/index.js +4 -0
- package/lib/module/cbor/cose/index.js.map +1 -0
- package/lib/module/cbor/cose/sign.js +23 -0
- package/lib/module/cbor/cose/sign.js.map +1 -0
- package/lib/module/cbor/index.js +13 -0
- package/lib/module/cbor/index.js.map +1 -0
- package/lib/module/index.js +8 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/iso18013/index.js +14 -0
- package/lib/module/iso18013/index.js.map +1 -0
- package/lib/module/iso18013/iso18013-5/README.md +234 -0
- package/lib/module/iso18013/iso18013-5/index.js +5 -0
- package/lib/module/iso18013/iso18013-5/index.js.map +1 -0
- package/lib/module/iso18013/iso18013-5/proximity.js +112 -0
- package/lib/module/iso18013/iso18013-5/proximity.js.map +1 -0
- package/lib/module/iso18013/iso18013-5/schema.js +79 -0
- package/lib/module/iso18013/iso18013-5/schema.js.map +1 -0
- package/lib/module/iso18013/iso18013-7/README.md +59 -0
- package/lib/module/iso18013/iso18013-7/index.js +4 -0
- package/lib/module/iso18013/iso18013-7/index.js.map +1 -0
- package/lib/module/iso18013/iso18013-7/remote.js +31 -0
- package/lib/module/iso18013/iso18013-7/remote.js.map +1 -0
- package/lib/module/iso18013/types.js +2 -0
- package/lib/module/iso18013/types.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/cbor/cbor/decoder.d.ts +35 -0
- package/lib/typescript/src/cbor/cbor/decoder.d.ts.map +1 -0
- package/lib/typescript/src/cbor/cbor/failure.d.ts +15 -0
- package/lib/typescript/src/cbor/cbor/failure.d.ts.map +1 -0
- package/lib/typescript/src/cbor/cbor/index.d.ts +4 -0
- package/lib/typescript/src/cbor/cbor/index.d.ts.map +1 -0
- package/lib/typescript/src/cbor/cbor/schema.d.ts +2420 -0
- package/lib/typescript/src/cbor/cbor/schema.d.ts.map +1 -0
- package/lib/typescript/src/cbor/cbor/schema.utils.d.ts +8 -0
- package/lib/typescript/src/cbor/cbor/schema.utils.d.ts.map +1 -0
- package/lib/typescript/src/cbor/cose/failure.d.ts +15 -0
- package/lib/typescript/src/cbor/cose/failure.d.ts.map +1 -0
- package/lib/typescript/src/cbor/cose/index.d.ts +3 -0
- package/lib/typescript/src/cbor/cose/index.d.ts.map +1 -0
- package/lib/typescript/src/cbor/cose/sign.d.ts +19 -0
- package/lib/typescript/src/cbor/cose/sign.d.ts.map +1 -0
- package/lib/typescript/src/cbor/index.d.ts +2 -0
- package/lib/typescript/src/cbor/index.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +6 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/iso18013/index.d.ts +3 -0
- package/lib/typescript/src/iso18013/index.d.ts.map +1 -0
- package/lib/typescript/src/iso18013/iso18013-5/index.d.ts +4 -0
- package/lib/typescript/src/iso18013/iso18013-5/index.d.ts.map +1 -0
- package/lib/typescript/src/iso18013/iso18013-5/proximity.d.ts +88 -0
- package/lib/typescript/src/iso18013/iso18013-5/proximity.d.ts.map +1 -0
- package/lib/typescript/src/iso18013/iso18013-5/schema.d.ts +85 -0
- package/lib/typescript/src/iso18013/iso18013-5/schema.d.ts.map +1 -0
- package/lib/typescript/src/iso18013/iso18013-7/index.d.ts +3 -0
- package/lib/typescript/src/iso18013/iso18013-7/index.d.ts.map +1 -0
- package/lib/typescript/src/iso18013/iso18013-7/remote.d.ts +29 -0
- package/lib/typescript/src/iso18013/iso18013-7/remote.d.ts.map +1 -0
- package/lib/typescript/src/iso18013/types.d.ts +16 -0
- package/lib/typescript/src/iso18013/types.d.ts.map +1 -0
- package/package.json +163 -0
- package/src/cbor/cbor/README.md +95 -0
- package/src/cbor/cbor/decoder.ts +56 -0
- package/src/cbor/cbor/failure.ts +18 -0
- package/src/cbor/cbor/index.ts +9 -0
- package/src/cbor/cbor/schema.ts +150 -0
- package/src/cbor/cbor/schema.utils.ts +13 -0
- package/src/cbor/cose/README.md +53 -0
- package/src/cbor/cose/failure.ts +20 -0
- package/src/cbor/cose/index.ts +2 -0
- package/src/cbor/cose/sign.ts +25 -0
- package/src/cbor/index.ts +18 -0
- package/src/index.tsx +5 -0
- package/src/iso18013/index.ts +25 -0
- package/src/iso18013/iso18013-5/README.md +234 -0
- package/src/iso18013/iso18013-5/index.ts +23 -0
- package/src/iso18013/iso18013-5/proximity.ts +134 -0
- package/src/iso18013/iso18013-5/schema.ts +87 -0
- package/src/iso18013/iso18013-7/README.md +59 -0
- package/src/iso18013/iso18013-7/index.ts +7 -0
- package/src/iso18013/iso18013-7/remote.ts +54 -0
- package/src/iso18013/types.ts +16 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = "IoReactNativeIso18013"
|
|
7
|
+
s.version = package["version"]
|
|
8
|
+
s.summary = package["description"]
|
|
9
|
+
s.homepage = package["homepage"]
|
|
10
|
+
s.license = package["license"]
|
|
11
|
+
s.authors = package["author"]
|
|
12
|
+
|
|
13
|
+
s.platforms = { :ios => min_ios_version_supported }
|
|
14
|
+
s.source = { :git => "https://github.com/pagopa/io-react-native-iso18013.git", :tag => "#{s.version}" }
|
|
15
|
+
|
|
16
|
+
s.source_files = "ios/**/*.{h,m,mm,swift}"
|
|
17
|
+
|
|
18
|
+
# Module dependencies
|
|
19
|
+
s.dependency "IOWalletCBOR", "~> 0.2.1"
|
|
20
|
+
s.dependency "IOWalletProximity", "~> 1.2.2"
|
|
21
|
+
|
|
22
|
+
# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
|
|
23
|
+
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
|
|
24
|
+
if respond_to?(:install_modules_dependencies, true)
|
|
25
|
+
install_modules_dependencies(s)
|
|
26
|
+
else
|
|
27
|
+
s.dependency "React-Core"
|
|
28
|
+
end
|
|
29
|
+
end
|
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 LazyAfternoons
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# @pagopa/io-react-native-iso18013
|
|
2
|
+
|
|
3
|
+
This library provides a React Native module based on [iso18013-android](https://github.com/pagopa/iso18013-android) and [iso18013-ios](https://github.com/pagopa/iso18013-ios) which allows proximity presentation according to the ISO 18013-5 standard, remote presentation according to the ISO 18013-7 standard, decoding of CBOR data and management of COSE verify and sign operations.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @pagopa/io-react-native-iso18013
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
Each module is documented in its own README file:
|
|
14
|
+
|
|
15
|
+
- [ISO18013-5](src/iso18013/iso18013-5/README.md): Proximity presentation according to the ISO 18013-5 standard;
|
|
16
|
+
- [ISO18013-7](src/iso18013/iso18013-7/README.md): Remote presentation according to the ISO 18013-7 standard;
|
|
17
|
+
- [CBOR](src/cbor/cbor/README.md): Decoding of CBOR data into readable objects;
|
|
18
|
+
- [COSE](src/cbor/cose/README.md): Management of COSE verify and sign operations.
|
|
19
|
+
|
|
20
|
+
## Contributing
|
|
21
|
+
|
|
22
|
+
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
|
|
23
|
+
|
|
24
|
+
## License
|
|
25
|
+
|
|
26
|
+
MIT
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
ext.getExtOrDefault = {name ->
|
|
3
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['IoReactNativeIso18013_' + name]
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
repositories {
|
|
7
|
+
google()
|
|
8
|
+
mavenCentral()
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
dependencies {
|
|
12
|
+
classpath "com.android.tools.build:gradle:8.7.2"
|
|
13
|
+
// noinspection DifferentKotlinGradleVersion
|
|
14
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
apply plugin: "com.android.library"
|
|
20
|
+
apply plugin: "kotlin-android"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def getExtOrIntegerDefault(name) {
|
|
24
|
+
return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["IoReactNativeIso18013_" + name]).toInteger()
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
def supportsNamespace() {
|
|
28
|
+
def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
|
|
29
|
+
def major = parsed[0].toInteger()
|
|
30
|
+
def minor = parsed[1].toInteger()
|
|
31
|
+
|
|
32
|
+
// Namespace support was added in 7.3.0
|
|
33
|
+
return (major == 7 && minor >= 3) || major >= 8
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
android {
|
|
37
|
+
if (supportsNamespace()) {
|
|
38
|
+
namespace "com.ioreactnativeiso18013"
|
|
39
|
+
|
|
40
|
+
sourceSets {
|
|
41
|
+
main {
|
|
42
|
+
manifest.srcFile "src/main/AndroidManifestNew.xml"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
|
|
48
|
+
|
|
49
|
+
defaultConfig {
|
|
50
|
+
minSdkVersion getExtOrIntegerDefault("minSdkVersion")
|
|
51
|
+
targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
buildTypes {
|
|
55
|
+
release {
|
|
56
|
+
minifyEnabled false
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
lintOptions {
|
|
61
|
+
disable "GradleCompatible"
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
compileOptions {
|
|
65
|
+
sourceCompatibility JavaVersion.VERSION_1_8
|
|
66
|
+
targetCompatibility JavaVersion.VERSION_1_8
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
repositories {
|
|
71
|
+
mavenCentral()
|
|
72
|
+
google()
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
def kotlin_version = getExtOrDefault("kotlinVersion")
|
|
76
|
+
|
|
77
|
+
dependencies {
|
|
78
|
+
implementation "com.facebook.react:react-android"
|
|
79
|
+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
80
|
+
implementation "it.pagopa.io.wallet.proximity:proximity:2.0.0"
|
|
81
|
+
implementation "it.pagopa.io.wallet.cbor:cbor:1.3.0"
|
|
82
|
+
}
|
|
83
|
+
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
package com.ioreactnativeiso18013
|
|
2
|
+
|
|
3
|
+
import kotlin.io.encoding.Base64
|
|
4
|
+
import kotlin.io.encoding.ExperimentalEncodingApi
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* This singleton class contains a set of utilities for encoding and decoding base64 and base64url
|
|
8
|
+
* strings. Some functions are simple wrappers in order to share it between modules and having a
|
|
9
|
+
* centralized class in case we'd like to change the underlying implementation.
|
|
10
|
+
* Currently it is based on [kotlin.io.encoding.Base64].
|
|
11
|
+
*/
|
|
12
|
+
object Base64Utils {
|
|
13
|
+
@OptIn(ExperimentalEncodingApi::class)
|
|
14
|
+
fun decodeBase64AndBase64Url(base: String): ByteArray {
|
|
15
|
+
return try {
|
|
16
|
+
/*
|
|
17
|
+
* Try to decode it as base64url and return it
|
|
18
|
+
* We set the padding as optional as RFC 4648 section 5 says
|
|
19
|
+
* The pad character "=" is typically percent-encoded when used in an
|
|
20
|
+
* URI [9], but if the data length is known implicitly, this can be
|
|
21
|
+
* avoided by skipping the padding; see section 3.2
|
|
22
|
+
*/
|
|
23
|
+
return Base64.UrlSafe.withPadding(Base64.PaddingOption.PRESENT_OPTIONAL).decode(base)
|
|
24
|
+
} catch (_: IllegalArgumentException) {
|
|
25
|
+
// Not base64url, it might be base64 or an invalid string
|
|
26
|
+
try {
|
|
27
|
+
// Try standard Base64 decoding and return it
|
|
28
|
+
Base64.Default.decode(base)
|
|
29
|
+
} catch (e: IllegalArgumentException) {
|
|
30
|
+
throw IllegalArgumentException("Input is not valid Base64 or Base64URL", e)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Wrapper method which encodes a ByteArray in a base64 string.
|
|
37
|
+
* This allows to change the underlying implementation here without changing it in the whole project.
|
|
38
|
+
* @param buffer - The ByteArray to be converted
|
|
39
|
+
* @returns A base64 encoded string representing the buffer
|
|
40
|
+
*/
|
|
41
|
+
@OptIn(ExperimentalEncodingApi::class)
|
|
42
|
+
fun encodeBase64(buffer: ByteArray): String {
|
|
43
|
+
return Base64.Default.encode(buffer)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Wrapper method which decodes a ByteArray in a base64 string.
|
|
48
|
+
* This allows to change the underlying implementation here without changing it in the whole project.
|
|
49
|
+
* @param buffer - The string to be converted
|
|
50
|
+
* @returns A buffer representing the base64 string
|
|
51
|
+
*/
|
|
52
|
+
@OptIn(ExperimentalEncodingApi::class)
|
|
53
|
+
fun decodeBase64(base64: String): ByteArray {
|
|
54
|
+
return Base64.Default.decode(base64)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
package com.ioreactnativeiso18013
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
4
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
5
|
+
import com.facebook.react.bridge.ReactMethod
|
|
6
|
+
import com.facebook.react.bridge.Promise
|
|
7
|
+
import com.facebook.react.bridge.ReadableMap
|
|
8
|
+
import com.facebook.react.bridge.WritableMap
|
|
9
|
+
import com.facebook.react.bridge.WritableNativeMap
|
|
10
|
+
import it.pagopa.io.wallet.cbor.cose.COSEManager
|
|
11
|
+
import it.pagopa.io.wallet.cbor.cose.FailureReason
|
|
12
|
+
import it.pagopa.io.wallet.cbor.cose.SignWithCOSEResult
|
|
13
|
+
import it.pagopa.io.wallet.cbor.parser.CBorParser
|
|
14
|
+
|
|
15
|
+
class IoReactNativeCborModule(reactContext: ReactApplicationContext) :
|
|
16
|
+
ReactContextBaseJavaModule(reactContext) {
|
|
17
|
+
|
|
18
|
+
override fun getName(): String {
|
|
19
|
+
return NAME
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@ReactMethod
|
|
23
|
+
fun decode(data: String, promise: Promise) {
|
|
24
|
+
val buffer = try {
|
|
25
|
+
Base64Utils.decodeBase64AndBase64Url(data)
|
|
26
|
+
} catch (e: Exception) {
|
|
27
|
+
ModuleException.INVALID_ENCODING.reject(
|
|
28
|
+
promise,
|
|
29
|
+
Pair(ERROR_USER_INFO_KEY, e.message.orEmpty())
|
|
30
|
+
)
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
CBorParser(buffer).toJson()?.let {
|
|
36
|
+
promise.resolve(it)
|
|
37
|
+
} ?: run {
|
|
38
|
+
ModuleException.UNABLE_TO_DECODE.reject(promise)
|
|
39
|
+
}
|
|
40
|
+
} catch (e: Exception) {
|
|
41
|
+
ModuleException.UNKNOWN_EXCEPTION.reject(
|
|
42
|
+
promise,
|
|
43
|
+
Pair(ERROR_USER_INFO_KEY, e.message.orEmpty())
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@ReactMethod
|
|
49
|
+
fun decodeDocuments(data: String, promise: Promise) {
|
|
50
|
+
val buffer = try {
|
|
51
|
+
Base64Utils.decodeBase64AndBase64Url(data)
|
|
52
|
+
} catch (e: Exception) {
|
|
53
|
+
ModuleException.INVALID_ENCODING.reject(
|
|
54
|
+
promise,
|
|
55
|
+
Pair(ERROR_USER_INFO_KEY, e.message.orEmpty())
|
|
56
|
+
)
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
CBorParser(buffer).documentsCborToJson(separateElementIdentifier = true, onComplete = {
|
|
61
|
+
promise.resolve(it)
|
|
62
|
+
}) { ex ->
|
|
63
|
+
ModuleException.UNABLE_TO_DECODE.reject(
|
|
64
|
+
promise,
|
|
65
|
+
Pair(ERROR_USER_INFO_KEY, ex.message.orEmpty())
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
} catch (e: Exception) {
|
|
69
|
+
ModuleException.UNKNOWN_EXCEPTION.reject(
|
|
70
|
+
promise,
|
|
71
|
+
Pair(ERROR_USER_INFO_KEY, e.message.orEmpty())
|
|
72
|
+
)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
@ReactMethod
|
|
77
|
+
fun decodeIssuerSigned(issuerSigned: String, promise: Promise) {
|
|
78
|
+
val buffer = try {
|
|
79
|
+
Base64Utils.decodeBase64AndBase64Url(issuerSigned)
|
|
80
|
+
} catch (e: Exception) {
|
|
81
|
+
ModuleException.INVALID_ENCODING.reject(
|
|
82
|
+
promise,
|
|
83
|
+
Pair(ERROR_USER_INFO_KEY, e.message.orEmpty())
|
|
84
|
+
)
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
CBorParser(buffer).issuerSignedCborToJson(separateElementIdentifier = true).let {
|
|
89
|
+
if (it == null) {
|
|
90
|
+
ModuleException.UNABLE_TO_DECODE.reject(
|
|
91
|
+
promise,
|
|
92
|
+
Pair(ERROR_USER_INFO_KEY, "Unable to decode passed CBOR")
|
|
93
|
+
)
|
|
94
|
+
return
|
|
95
|
+
}
|
|
96
|
+
promise.resolve(it)
|
|
97
|
+
}
|
|
98
|
+
} catch (e: Exception) {
|
|
99
|
+
ModuleException.UNKNOWN_EXCEPTION.reject(
|
|
100
|
+
promise,
|
|
101
|
+
Pair(ERROR_USER_INFO_KEY, e.message.orEmpty())
|
|
102
|
+
)
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
@ReactMethod
|
|
107
|
+
fun sign(payload: String, keyTag: String, promise: Promise) {
|
|
108
|
+
val data = try {
|
|
109
|
+
Base64Utils.decodeBase64AndBase64Url(payload)
|
|
110
|
+
} catch (e: Exception) {
|
|
111
|
+
ModuleException.INVALID_ENCODING.reject(
|
|
112
|
+
promise,
|
|
113
|
+
Pair(ERROR_USER_INFO_KEY, e.message.orEmpty())
|
|
114
|
+
)
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
try {
|
|
119
|
+
val result = COSEManager().signWithCOSE(
|
|
120
|
+
data = data,
|
|
121
|
+
alias = keyTag
|
|
122
|
+
)
|
|
123
|
+
when (result) {
|
|
124
|
+
is SignWithCOSEResult.Failure -> {
|
|
125
|
+
when (result.reason) {
|
|
126
|
+
FailureReason.NO_KEY -> ModuleException.PUBLIC_KEY_NOT_FOUND.reject(
|
|
127
|
+
promise,
|
|
128
|
+
Pair(ERROR_USER_INFO_KEY, result.reason.msg)
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
FailureReason.FAIL_TO_SIGN -> ModuleException.UNABLE_TO_SIGN.reject(
|
|
132
|
+
promise,
|
|
133
|
+
Pair(ERROR_USER_INFO_KEY, result.reason.msg)
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
else -> ModuleException.UNKNOWN_EXCEPTION.reject(
|
|
137
|
+
promise,
|
|
138
|
+
Pair(ERROR_USER_INFO_KEY, result.reason.msg)
|
|
139
|
+
)
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
is SignWithCOSEResult.Success -> {
|
|
144
|
+
promise.resolve(Base64Utils.encodeBase64(result.signature))
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
} catch (e: Exception) {
|
|
148
|
+
ModuleException.UNKNOWN_EXCEPTION.reject(
|
|
149
|
+
promise,
|
|
150
|
+
Pair(ERROR_USER_INFO_KEY, e.message.orEmpty())
|
|
151
|
+
)
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
@ReactMethod
|
|
156
|
+
fun verify(sign1Data: String, publicKey: ReadableMap, promise: Promise) {
|
|
157
|
+
val data = try {
|
|
158
|
+
Base64Utils.decodeBase64AndBase64Url(sign1Data)
|
|
159
|
+
} catch (e: Exception) {
|
|
160
|
+
ModuleException.INVALID_ENCODING.reject(
|
|
161
|
+
promise,
|
|
162
|
+
Pair(ERROR_USER_INFO_KEY, e.message.orEmpty())
|
|
163
|
+
)
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
try {
|
|
168
|
+
val result = COSEManager().verifySign1FromJWK(
|
|
169
|
+
dataSigned = data,
|
|
170
|
+
jwk = publicKey.toString()
|
|
171
|
+
)
|
|
172
|
+
promise.resolve(result)
|
|
173
|
+
} catch (e: Exception) {
|
|
174
|
+
ModuleException.UNKNOWN_EXCEPTION.reject(
|
|
175
|
+
promise,
|
|
176
|
+
Pair(ERROR_USER_INFO_KEY, e.message.orEmpty())
|
|
177
|
+
)
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
companion object {
|
|
182
|
+
const val NAME = "IoReactNativeCbor"
|
|
183
|
+
const val ERROR_USER_INFO_KEY = "error"
|
|
184
|
+
|
|
185
|
+
private enum class ModuleException(
|
|
186
|
+
val ex: Exception
|
|
187
|
+
) {
|
|
188
|
+
UNABLE_TO_DECODE(Exception("UNABLE_TO_DECODE")),
|
|
189
|
+
PUBLIC_KEY_NOT_FOUND(Exception("PUBLIC_KEY_NOT_FOUND")),
|
|
190
|
+
UNABLE_TO_SIGN(Exception("UNABLE_TO_SIGN")),
|
|
191
|
+
INVALID_ENCODING(Exception("INVALID_ENCODING")),
|
|
192
|
+
UNKNOWN_EXCEPTION(Exception("UNKNOWN_EXCEPTION"));
|
|
193
|
+
|
|
194
|
+
fun reject(
|
|
195
|
+
promise: Promise, vararg args: Pair<String, String>
|
|
196
|
+
) {
|
|
197
|
+
exMap(*args).let {
|
|
198
|
+
promise.reject(it.first, ex.message, it.second)
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
private fun exMap(vararg args: Pair<String, String>): Pair<String, WritableMap> {
|
|
203
|
+
val writableMap = WritableNativeMap()
|
|
204
|
+
args.forEach { writableMap.putString(it.first, it.second) }
|
|
205
|
+
return Pair(this.ex.message ?: "UNKNOWN", writableMap)
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|