@novastera-oss/nitro-metamask 0.2.6 → 0.3.2
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/LICENSE +21 -201
- package/NitroMetamask.podspec +1 -1
- package/README.md +16 -249
- package/android/CMakeLists.txt +3 -0
- package/android/build.gradle +25 -19
- package/android/fix-prefab.gradle +1 -1
- package/android/gradle.properties +2 -2
- package/android/src/main/java/com/{margelo/nitro/nitrometamask/HybridMetamaskConnector.kt → nitrometamask/HybridNitroMetamask.kt} +43 -24
- package/android/src/main/java/com/nitrometamask/MetamaskContextHolder.kt +15 -0
- package/android/src/main/java/com/nitrometamask/NitroMetamaskPackage.kt +53 -0
- package/ios/Bridge.h +2 -2
- package/ios/{HybridMetamaskConnector.swift → HybridNitroMetamask.swift} +1 -2
- package/lib/commonjs/index.js +20 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/specs/nitro-metamask.nitro.js +6 -0
- package/lib/commonjs/specs/nitro-metamask.nitro.js.map +1 -0
- package/lib/module/index.js +16 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/specs/nitro-metamask.nitro.js +4 -0
- package/lib/module/specs/nitro-metamask.nitro.js.map +1 -0
- package/lib/typescript/src/index.d.ts +15 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/{MetamaskConnector.nitro.d.ts → typescript/src/specs/nitro-metamask.nitro.d.ts} +3 -2
- package/lib/typescript/src/specs/nitro-metamask.nitro.d.ts.map +1 -0
- package/nitro.json +4 -4
- package/nitrogen/generated/android/NitroMetamask+autolinking.cmake +2 -2
- package/nitrogen/generated/android/NitroMetamaskOnLoad.cpp +4 -4
- package/nitrogen/generated/android/c++/{JHybridMetamaskConnectorSpec.cpp → JHybridNitroMetamaskSpec.cpp} +10 -10
- package/nitrogen/generated/android/c++/{JHybridMetamaskConnectorSpec.hpp → JHybridNitroMetamaskSpec.hpp} +10 -10
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrometamask/{HybridMetamaskConnectorSpec.kt → HybridNitroMetamaskSpec.kt} +6 -6
- package/nitrogen/generated/ios/NitroMetamask-Swift-Cxx-Bridge.cpp +9 -9
- package/nitrogen/generated/ios/NitroMetamask-Swift-Cxx-Bridge.hpp +13 -13
- package/nitrogen/generated/ios/NitroMetamask-Swift-Cxx-Umbrella.hpp +5 -5
- package/nitrogen/generated/ios/NitroMetamaskAutolinking.mm +3 -3
- package/nitrogen/generated/ios/NitroMetamaskAutolinking.swift +6 -6
- package/nitrogen/generated/ios/c++/{HybridMetamaskConnectorSpecSwift.cpp → HybridNitroMetamaskSpecSwift.cpp} +2 -2
- package/nitrogen/generated/ios/c++/{HybridMetamaskConnectorSpecSwift.hpp → HybridNitroMetamaskSpecSwift.hpp} +12 -12
- package/nitrogen/generated/ios/swift/HybridNitroMetamaskSpec.swift +57 -0
- package/nitrogen/generated/ios/swift/{HybridMetamaskConnectorSpec_cxx.swift → HybridNitroMetamaskSpec_cxx.swift} +18 -18
- package/nitrogen/generated/shared/c++/{HybridMetamaskConnectorSpec.cpp → HybridNitroMetamaskSpec.cpp} +5 -5
- package/nitrogen/generated/shared/c++/{HybridMetamaskConnectorSpec.hpp → HybridNitroMetamaskSpec.hpp} +9 -9
- package/package.json +55 -39
- package/react-native.config.js +4 -1
- package/src/index.ts +14 -5
- package/src/specs/nitro-metamask.nitro.ts +11 -0
- package/android/src/main/java/com/margelo/nitro/nitrometamask/NitroMetamaskPackage.kt +0 -21
- package/lib/MetamaskConnector.nitro.js +0 -1
- package/lib/index.d.ts +0 -3
- package/lib/index.js +0 -2
- package/lib/specs/Example.nitro.d.ts +0 -0
- package/lib/specs/Example.nitro.js +0 -2
- package/nitrogen/generated/ios/swift/HybridMetamaskConnectorSpec.swift +0 -57
- package/src/MetamaskConnector.nitro.ts +0 -13
- package/src/specs/Example.nitro.ts +0 -1
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
package com.
|
|
1
|
+
package com.nitrometamask
|
|
2
2
|
|
|
3
3
|
import com.margelo.nitro.core.Promise
|
|
4
|
-
import com.margelo.nitro.
|
|
4
|
+
import com.margelo.nitro.nitrometamask.HybridNitroMetamaskSpec
|
|
5
|
+
import com.margelo.nitro.nitrometamask.ConnectResult
|
|
5
6
|
import io.metamask.androidsdk.Ethereum
|
|
6
7
|
import io.metamask.androidsdk.Result
|
|
7
8
|
import io.metamask.androidsdk.DappMetadata
|
|
8
9
|
import io.metamask.androidsdk.SDKOptions
|
|
9
10
|
import io.metamask.androidsdk.EthereumRequest
|
|
10
|
-
import io.metamask.androidsdk.EthereumMethod
|
|
11
11
|
import kotlinx.coroutines.suspendCancellableCoroutine
|
|
12
12
|
import kotlin.coroutines.resume
|
|
13
13
|
|
|
14
|
-
class
|
|
14
|
+
class HybridNitroMetamask : HybridNitroMetamaskSpec() {
|
|
15
15
|
// Initialize Ethereum SDK with Context, DappMetadata, and SDKOptions
|
|
16
16
|
// Based on: https://github.com/MetaMask/metamask-android-sdk
|
|
17
|
-
// Using
|
|
17
|
+
// Using MetamaskContextHolder for Context access (Nitro doesn't provide Context APIs)
|
|
18
|
+
// This pattern matches how other Nitro modules handle Context (VisionCamera, MMKV, etc.)
|
|
18
19
|
private val ethereum: Ethereum by lazy {
|
|
19
|
-
val context =
|
|
20
|
-
?: throw IllegalStateException("Application context not available")
|
|
20
|
+
val context = MetamaskContextHolder.get()
|
|
21
21
|
|
|
22
22
|
val dappMetadata = DappMetadata(
|
|
23
23
|
name = "Nitro MetaMask Connector",
|
|
@@ -73,11 +73,18 @@ class HybridMetamaskConnector : HybridMetamaskConnectorSpec() {
|
|
|
73
73
|
chainId = chainId
|
|
74
74
|
)
|
|
75
75
|
}
|
|
76
|
-
is Result.
|
|
77
|
-
|
|
76
|
+
is Result.Success.ItemMap -> {
|
|
77
|
+
// Handle ItemMap case (shouldn't happen for connect, but make exhaustive)
|
|
78
|
+
throw IllegalStateException("Unexpected ItemMap result from MetaMask connect")
|
|
79
|
+
}
|
|
80
|
+
is Result.Success.Items -> {
|
|
81
|
+
// Handle Items case (shouldn't happen for connect, but make exhaustive)
|
|
82
|
+
throw IllegalStateException("Unexpected Items result from MetaMask connect")
|
|
78
83
|
}
|
|
79
|
-
|
|
80
|
-
|
|
84
|
+
is Result.Error -> {
|
|
85
|
+
// Result.Error contains the error directly
|
|
86
|
+
val errorMessage = result.error?.message ?: result.error?.toString() ?: "MetaMask connection failed"
|
|
87
|
+
throw Exception(errorMessage)
|
|
81
88
|
}
|
|
82
89
|
}
|
|
83
90
|
}
|
|
@@ -87,15 +94,19 @@ class HybridMetamaskConnector : HybridMetamaskConnectorSpec() {
|
|
|
87
94
|
// Use Promise.async with coroutines for best practice in Nitro modules
|
|
88
95
|
// Reference: https://nitro.margelo.com/docs/types/promises
|
|
89
96
|
return Promise.async {
|
|
90
|
-
//
|
|
91
|
-
//
|
|
92
|
-
// Based on SDK docs: ethereum.signMessage() requires address and message
|
|
97
|
+
// Verify connection state before attempting to sign
|
|
98
|
+
// MetaMask SDK requires an active connection to sign messages
|
|
93
99
|
val address = ethereum.selectedAddress
|
|
94
|
-
|
|
100
|
+
if (address.isNullOrEmpty()) {
|
|
101
|
+
throw IllegalStateException("No connected account. Please call connect() first to establish a connection with MetaMask.")
|
|
102
|
+
}
|
|
95
103
|
|
|
96
104
|
// Create EthereumRequest for personal_sign
|
|
105
|
+
// Based on MetaMask Android SDK docs: params are [account, message]
|
|
106
|
+
// Reference: https://github.com/MetaMask/metamask-android-sdk
|
|
107
|
+
// EthereumRequest constructor expects method as String
|
|
97
108
|
val request = EthereumRequest(
|
|
98
|
-
method =
|
|
109
|
+
method = "personal_sign",
|
|
99
110
|
params = listOf(address, message)
|
|
100
111
|
)
|
|
101
112
|
|
|
@@ -110,18 +121,26 @@ class HybridMetamaskConnector : HybridMetamaskConnectorSpec() {
|
|
|
110
121
|
|
|
111
122
|
when (result) {
|
|
112
123
|
is Result.Success.Item -> {
|
|
113
|
-
// Extract signature from
|
|
114
|
-
|
|
115
|
-
|
|
124
|
+
// Extract signature from response
|
|
125
|
+
// The signature should be a hex-encoded string (0x-prefixed)
|
|
126
|
+
val signature = result.value as? String
|
|
127
|
+
?: throw Exception("Invalid signature response format")
|
|
128
|
+
signature
|
|
116
129
|
}
|
|
117
|
-
is Result.
|
|
118
|
-
|
|
130
|
+
is Result.Success.ItemMap -> {
|
|
131
|
+
// Handle ItemMap case (shouldn't happen for signMessage, but make exhaustive)
|
|
132
|
+
throw IllegalStateException("Unexpected ItemMap result from MetaMask signMessage")
|
|
133
|
+
}
|
|
134
|
+
is Result.Success.Items -> {
|
|
135
|
+
// Handle Items case (shouldn't happen for signMessage, but make exhaustive)
|
|
136
|
+
throw IllegalStateException("Unexpected Items result from MetaMask signMessage")
|
|
119
137
|
}
|
|
120
|
-
|
|
121
|
-
|
|
138
|
+
is Result.Error -> {
|
|
139
|
+
// Result.Error contains the error directly
|
|
140
|
+
val errorMessage = result.error?.message ?: result.error?.toString() ?: "MetaMask signing failed"
|
|
141
|
+
throw Exception(errorMessage)
|
|
122
142
|
}
|
|
123
143
|
}
|
|
124
144
|
}
|
|
125
145
|
}
|
|
126
146
|
}
|
|
127
|
-
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
package com.nitrometamask
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
|
|
5
|
+
object MetamaskContextHolder {
|
|
6
|
+
private var context: Context? = null
|
|
7
|
+
|
|
8
|
+
fun initialize(ctx: Context) {
|
|
9
|
+
context = ctx.applicationContext
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
fun get(): Context {
|
|
13
|
+
return context ?: throw IllegalStateException("Context not initialized")
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
package com.nitrometamask
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.BaseReactPackage
|
|
4
|
+
import com.facebook.react.bridge.NativeModule
|
|
5
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
|
+
import com.facebook.react.module.model.ReactModuleInfo
|
|
7
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
8
|
+
import com.margelo.nitro.nitrometamask.NitroMetamaskOnLoad
|
|
9
|
+
|
|
10
|
+
class NitroMetamaskPackage : BaseReactPackage() {
|
|
11
|
+
@Volatile
|
|
12
|
+
private var contextInitialized = false
|
|
13
|
+
|
|
14
|
+
override fun getModule(
|
|
15
|
+
name: String,
|
|
16
|
+
reactContext: ReactApplicationContext
|
|
17
|
+
): NativeModule? {
|
|
18
|
+
// Initialize context on first call (thread-safe)
|
|
19
|
+
if (!contextInitialized) {
|
|
20
|
+
synchronized(this) {
|
|
21
|
+
if (!contextInitialized) {
|
|
22
|
+
MetamaskContextHolder.initialize(reactContext)
|
|
23
|
+
contextInitialized = true
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return null
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
|
|
31
|
+
// Register a dummy module name to ensure getModule() is called
|
|
32
|
+
// This guarantees context initialization
|
|
33
|
+
return ReactModuleInfoProvider {
|
|
34
|
+
mapOf(
|
|
35
|
+
"NitroMetamaskPackage" to ReactModuleInfo(
|
|
36
|
+
"NitroMetamaskPackage",
|
|
37
|
+
"NitroMetamaskPackage",
|
|
38
|
+
false, // canOverrideExistingModule
|
|
39
|
+
true, // needsEagerInit
|
|
40
|
+
true, // hasConstants
|
|
41
|
+
false, // isCxxModule
|
|
42
|
+
true // isTurboModule
|
|
43
|
+
)
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
companion object {
|
|
49
|
+
init {
|
|
50
|
+
NitroMetamaskOnLoad.initializeNative()
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
package/ios/Bridge.h
CHANGED
|
@@ -2,7 +2,7 @@ import NitroModules
|
|
|
2
2
|
import MetaMaskSDK
|
|
3
3
|
import Foundation
|
|
4
4
|
|
|
5
|
-
final class
|
|
5
|
+
final class HybridNitroMetamask: HybridNitroMetamaskSpec {
|
|
6
6
|
private let sdk = MetaMaskSDK.shared
|
|
7
7
|
|
|
8
8
|
func connect() -> Promise<ConnectResult> {
|
|
@@ -94,4 +94,3 @@ final class HybridMetamaskConnector: HybridMetamaskConnectorSpec {
|
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
-
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.NitroMetamask = void 0;
|
|
7
|
+
var _reactNativeNitroModules = require("react-native-nitro-modules");
|
|
8
|
+
/**
|
|
9
|
+
* NitroMetamask - MetaMask connector for React Native
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { NitroMetamask } from '@novastera-oss/nitro-metamask'
|
|
14
|
+
*
|
|
15
|
+
* const result = await NitroMetamask.connect()
|
|
16
|
+
* const signature = await NitroMetamask.signMessage('Hello')
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
const NitroMetamask = exports.NitroMetamask = _reactNativeNitroModules.NitroModules.createHybridObject('NitroMetamask');
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_reactNativeNitroModules","require","NitroMetamask","exports","NitroModules","createHybridObject"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;AAAA,IAAAA,wBAAA,GAAAC,OAAA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,aAAa,GAAAC,OAAA,CAAAD,aAAA,GAAGE,qCAAY,CAACC,kBAAkB,CAAoB,eAAe,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["specs/nitro-metamask.nitro.ts"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { NitroModules } from 'react-native-nitro-modules';
|
|
4
|
+
/**
|
|
5
|
+
* NitroMetamask - MetaMask connector for React Native
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { NitroMetamask } from '@novastera-oss/nitro-metamask'
|
|
10
|
+
*
|
|
11
|
+
* const result = await NitroMetamask.connect()
|
|
12
|
+
* const signature = await NitroMetamask.signMessage('Hello')
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export const NitroMetamask = NitroModules.createHybridObject('NitroMetamask');
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["NitroModules","NitroMetamask","createHybridObject"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,SAASA,YAAY,QAAQ,4BAA4B;AAGzD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,aAAa,GAAGD,YAAY,CAACE,kBAAkB,CAAoB,eAAe,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["specs/nitro-metamask.nitro.ts"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { NitroMetamask as NitroMetamaskSpec, ConnectResult } from './specs/nitro-metamask.nitro';
|
|
2
|
+
/**
|
|
3
|
+
* NitroMetamask - MetaMask connector for React Native
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { NitroMetamask } from '@novastera-oss/nitro-metamask'
|
|
8
|
+
*
|
|
9
|
+
* const result = await NitroMetamask.connect()
|
|
10
|
+
* const signature = await NitroMetamask.signMessage('Hello')
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export declare const NitroMetamask: NitroMetamaskSpec;
|
|
14
|
+
export type { ConnectResult, NitroMetamaskSpec };
|
|
15
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,IAAI,iBAAiB,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAErG;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa,mBAAsE,CAAA;AAEhG,YAAY,EAAE,aAAa,EAAE,iBAAiB,EAAE,CAAA"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type HybridObject } from 'react-native-nitro-modules';
|
|
2
2
|
export interface ConnectResult {
|
|
3
3
|
address: string;
|
|
4
4
|
chainId: number;
|
|
5
5
|
}
|
|
6
|
-
export interface
|
|
6
|
+
export interface NitroMetamask extends HybridObject<{
|
|
7
7
|
ios: 'swift';
|
|
8
8
|
android: 'kotlin';
|
|
9
9
|
}> {
|
|
10
10
|
connect(): Promise<ConnectResult>;
|
|
11
11
|
signMessage(message: string): Promise<string>;
|
|
12
12
|
}
|
|
13
|
+
//# sourceMappingURL=nitro-metamask.nitro.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nitro-metamask.nitro.d.ts","sourceRoot":"","sources":["../../../../src/specs/nitro-metamask.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,4BAA4B,CAAA;AAE9D,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,MAAM,WAAW,aAAc,SAAQ,YAAY,CAAC;IAAE,GAAG,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,QAAQ,CAAA;CAAE,CAAC;IACtF,OAAO,IAAI,OAAO,CAAC,aAAa,CAAC,CAAA;IACjC,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;CAC9C"}
|
package/nitro.json
CHANGED
|
@@ -13,12 +13,12 @@
|
|
|
13
13
|
"androidCxxLibName": "NitroMetamask"
|
|
14
14
|
},
|
|
15
15
|
"autolinking": {
|
|
16
|
-
"
|
|
17
|
-
"swift": "
|
|
18
|
-
"kotlin": "
|
|
16
|
+
"NitroMetamask": {
|
|
17
|
+
"swift": "HybridNitroMetamask",
|
|
18
|
+
"kotlin": "HybridNitroMetamask"
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"ignorePaths": [
|
|
22
22
|
"**/node_modules"
|
|
23
23
|
]
|
|
24
|
-
}
|
|
24
|
+
}
|
|
@@ -33,9 +33,9 @@ target_sources(
|
|
|
33
33
|
# Autolinking Setup
|
|
34
34
|
../nitrogen/generated/android/NitroMetamaskOnLoad.cpp
|
|
35
35
|
# Shared Nitrogen C++ sources
|
|
36
|
-
../nitrogen/generated/shared/c++/
|
|
36
|
+
../nitrogen/generated/shared/c++/HybridNitroMetamaskSpec.cpp
|
|
37
37
|
# Android-specific Nitrogen C++ sources
|
|
38
|
-
../nitrogen/generated/android/c++/
|
|
38
|
+
../nitrogen/generated/android/c++/JHybridNitroMetamaskSpec.cpp
|
|
39
39
|
)
|
|
40
40
|
|
|
41
41
|
# From node_modules/react-native/ReactAndroid/cmake-utils/folly-flags.cmake
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
#include <fbjni/fbjni.h>
|
|
16
16
|
#include <NitroModules/HybridObjectRegistry.hpp>
|
|
17
17
|
|
|
18
|
-
#include "
|
|
18
|
+
#include "JHybridNitroMetamaskSpec.hpp"
|
|
19
19
|
#include <NitroModules/DefaultConstructableObject.hpp>
|
|
20
20
|
|
|
21
21
|
namespace margelo::nitro::nitrometamask {
|
|
@@ -27,13 +27,13 @@ int initialize(JavaVM* vm) {
|
|
|
27
27
|
|
|
28
28
|
return facebook::jni::initialize(vm, [] {
|
|
29
29
|
// Register native JNI methods
|
|
30
|
-
margelo::nitro::nitrometamask::
|
|
30
|
+
margelo::nitro::nitrometamask::JHybridNitroMetamaskSpec::registerNatives();
|
|
31
31
|
|
|
32
32
|
// Register Nitro Hybrid Objects
|
|
33
33
|
HybridObjectRegistry::registerHybridObjectConstructor(
|
|
34
|
-
"
|
|
34
|
+
"NitroMetamask",
|
|
35
35
|
[]() -> std::shared_ptr<HybridObject> {
|
|
36
|
-
static DefaultConstructableObject<
|
|
36
|
+
static DefaultConstructableObject<JHybridNitroMetamaskSpec::javaobject> object("com/margelo/nitro/nitrometamask/HybridNitroMetamask");
|
|
37
37
|
auto instance = object.create();
|
|
38
38
|
return instance->cthis()->shared();
|
|
39
39
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
///
|
|
2
|
-
///
|
|
2
|
+
/// JHybridNitroMetamaskSpec.cpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
5
|
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
6
|
///
|
|
7
7
|
|
|
8
|
-
#include "
|
|
8
|
+
#include "JHybridNitroMetamaskSpec.hpp"
|
|
9
9
|
|
|
10
10
|
// Forward declaration of `ConnectResult` to properly resolve imports.
|
|
11
11
|
namespace margelo::nitro::nitrometamask { struct ConnectResult; }
|
|
@@ -18,27 +18,27 @@ namespace margelo::nitro::nitrometamask { struct ConnectResult; }
|
|
|
18
18
|
|
|
19
19
|
namespace margelo::nitro::nitrometamask {
|
|
20
20
|
|
|
21
|
-
jni::local_ref<
|
|
21
|
+
jni::local_ref<JHybridNitroMetamaskSpec::jhybriddata> JHybridNitroMetamaskSpec::initHybrid(jni::alias_ref<jhybridobject> jThis) {
|
|
22
22
|
return makeCxxInstance(jThis);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
void
|
|
25
|
+
void JHybridNitroMetamaskSpec::registerNatives() {
|
|
26
26
|
registerHybrid({
|
|
27
|
-
makeNativeMethod("initHybrid",
|
|
27
|
+
makeNativeMethod("initHybrid", JHybridNitroMetamaskSpec::initHybrid),
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
size_t
|
|
31
|
+
size_t JHybridNitroMetamaskSpec::getExternalMemorySize() noexcept {
|
|
32
32
|
static const auto method = javaClassStatic()->getMethod<jlong()>("getMemorySize");
|
|
33
33
|
return method(_javaPart);
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
void
|
|
36
|
+
void JHybridNitroMetamaskSpec::dispose() noexcept {
|
|
37
37
|
static const auto method = javaClassStatic()->getMethod<void()>("dispose");
|
|
38
38
|
method(_javaPart);
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
std::string
|
|
41
|
+
std::string JHybridNitroMetamaskSpec::toString() {
|
|
42
42
|
static const auto method = javaClassStatic()->getMethod<jni::JString()>("toString");
|
|
43
43
|
auto javaString = method(_javaPart);
|
|
44
44
|
return javaString->toStdString();
|
|
@@ -48,7 +48,7 @@ namespace margelo::nitro::nitrometamask {
|
|
|
48
48
|
|
|
49
49
|
|
|
50
50
|
// Methods
|
|
51
|
-
std::shared_ptr<Promise<ConnectResult>>
|
|
51
|
+
std::shared_ptr<Promise<ConnectResult>> JHybridNitroMetamaskSpec::connect() {
|
|
52
52
|
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>()>("connect");
|
|
53
53
|
auto __result = method(_javaPart);
|
|
54
54
|
return [&]() {
|
|
@@ -64,7 +64,7 @@ namespace margelo::nitro::nitrometamask {
|
|
|
64
64
|
return __promise;
|
|
65
65
|
}();
|
|
66
66
|
}
|
|
67
|
-
std::shared_ptr<Promise<std::string>>
|
|
67
|
+
std::shared_ptr<Promise<std::string>> JHybridNitroMetamaskSpec::signMessage(const std::string& message) {
|
|
68
68
|
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JString> /* message */)>("signMessage");
|
|
69
69
|
auto __result = method(_javaPart, jni::make_jstring(message));
|
|
70
70
|
return [&]() {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
///
|
|
2
|
-
///
|
|
2
|
+
/// HybridNitroMetamaskSpec.hpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
5
|
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
#include <NitroModules/JHybridObject.hpp>
|
|
11
11
|
#include <fbjni/fbjni.h>
|
|
12
|
-
#include "
|
|
12
|
+
#include "HybridNitroMetamaskSpec.hpp"
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
|
|
@@ -18,22 +18,22 @@ namespace margelo::nitro::nitrometamask {
|
|
|
18
18
|
|
|
19
19
|
using namespace facebook;
|
|
20
20
|
|
|
21
|
-
class
|
|
22
|
-
|
|
21
|
+
class JHybridNitroMetamaskSpec: public jni::HybridClass<JHybridNitroMetamaskSpec, JHybridObject>,
|
|
22
|
+
public virtual HybridNitroMetamaskSpec {
|
|
23
23
|
public:
|
|
24
|
-
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/nitrometamask/
|
|
24
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/nitrometamask/HybridNitroMetamaskSpec;";
|
|
25
25
|
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject> jThis);
|
|
26
26
|
static void registerNatives();
|
|
27
27
|
|
|
28
28
|
protected:
|
|
29
29
|
// C++ constructor (called from Java via `initHybrid()`)
|
|
30
|
-
explicit
|
|
31
|
-
HybridObject(
|
|
30
|
+
explicit JHybridNitroMetamaskSpec(jni::alias_ref<jhybridobject> jThis) :
|
|
31
|
+
HybridObject(HybridNitroMetamaskSpec::TAG),
|
|
32
32
|
HybridBase(jThis),
|
|
33
33
|
_javaPart(jni::make_global(jThis)) {}
|
|
34
34
|
|
|
35
35
|
public:
|
|
36
|
-
~
|
|
36
|
+
~JHybridNitroMetamaskSpec() override {
|
|
37
37
|
// Hermes GC can destroy JS objects on a non-JNI Thread.
|
|
38
38
|
jni::ThreadScope::WithClassLoader([&] { _javaPart.reset(); });
|
|
39
39
|
}
|
|
@@ -44,7 +44,7 @@ namespace margelo::nitro::nitrometamask {
|
|
|
44
44
|
std::string toString() override;
|
|
45
45
|
|
|
46
46
|
public:
|
|
47
|
-
inline const jni::global_ref<
|
|
47
|
+
inline const jni::global_ref<JHybridNitroMetamaskSpec::javaobject>& getJavaPart() const noexcept {
|
|
48
48
|
return _javaPart;
|
|
49
49
|
}
|
|
50
50
|
|
|
@@ -60,7 +60,7 @@ namespace margelo::nitro::nitrometamask {
|
|
|
60
60
|
private:
|
|
61
61
|
friend HybridBase;
|
|
62
62
|
using HybridBase::HybridBase;
|
|
63
|
-
jni::global_ref<
|
|
63
|
+
jni::global_ref<JHybridNitroMetamaskSpec::javaobject> _javaPart;
|
|
64
64
|
};
|
|
65
65
|
|
|
66
66
|
} // namespace margelo::nitro::nitrometamask
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
///
|
|
2
|
-
///
|
|
2
|
+
/// HybridNitroMetamaskSpec.kt
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
5
|
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
@@ -14,8 +14,8 @@ import com.margelo.nitro.core.Promise
|
|
|
14
14
|
import com.margelo.nitro.core.HybridObject
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
|
-
* A Kotlin class representing the
|
|
18
|
-
* Implement this abstract class to create Kotlin-based instances of
|
|
17
|
+
* A Kotlin class representing the NitroMetamask HybridObject.
|
|
18
|
+
* Implement this abstract class to create Kotlin-based instances of NitroMetamask.
|
|
19
19
|
*/
|
|
20
20
|
@DoNotStrip
|
|
21
21
|
@Keep
|
|
@@ -24,7 +24,7 @@ import com.margelo.nitro.core.HybridObject
|
|
|
24
24
|
"RedundantSuppression", "RedundantUnitReturnType", "SimpleRedundantLet",
|
|
25
25
|
"LocalVariableName", "PropertyName", "PrivatePropertyName", "FunctionName"
|
|
26
26
|
)
|
|
27
|
-
abstract class
|
|
27
|
+
abstract class HybridNitroMetamaskSpec: HybridObject() {
|
|
28
28
|
@DoNotStrip
|
|
29
29
|
private var mHybridData: HybridData = initHybrid()
|
|
30
30
|
|
|
@@ -39,7 +39,7 @@ abstract class HybridMetamaskConnectorSpec: HybridObject() {
|
|
|
39
39
|
|
|
40
40
|
// Default implementation of `HybridObject.toString()`
|
|
41
41
|
override fun toString(): String {
|
|
42
|
-
return "[HybridObject
|
|
42
|
+
return "[HybridObject NitroMetamask]"
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
// Properties
|
|
@@ -57,6 +57,6 @@ abstract class HybridMetamaskConnectorSpec: HybridObject() {
|
|
|
57
57
|
private external fun initHybrid(): HybridData
|
|
58
58
|
|
|
59
59
|
companion object {
|
|
60
|
-
protected const val TAG = "
|
|
60
|
+
protected const val TAG = "HybridNitroMetamaskSpec"
|
|
61
61
|
}
|
|
62
62
|
}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
#include "NitroMetamask-Swift-Cxx-Bridge.hpp"
|
|
9
9
|
|
|
10
10
|
// Include C++ implementation defined types
|
|
11
|
-
#include "
|
|
11
|
+
#include "HybridNitroMetamaskSpecSwift.hpp"
|
|
12
12
|
#include "NitroMetamask-Swift-Cxx-Umbrella.hpp"
|
|
13
13
|
#include <NitroModules/NitroDefines.hpp>
|
|
14
14
|
|
|
@@ -38,19 +38,19 @@ namespace margelo::nitro::nitrometamask::bridge::swift {
|
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
// pragma MARK: std::shared_ptr<
|
|
42
|
-
std::shared_ptr<
|
|
43
|
-
NitroMetamask::
|
|
44
|
-
return std::make_shared<margelo::nitro::nitrometamask::
|
|
41
|
+
// pragma MARK: std::shared_ptr<HybridNitroMetamaskSpec>
|
|
42
|
+
std::shared_ptr<HybridNitroMetamaskSpec> create_std__shared_ptr_HybridNitroMetamaskSpec_(void* NON_NULL swiftUnsafePointer) noexcept {
|
|
43
|
+
NitroMetamask::HybridNitroMetamaskSpec_cxx swiftPart = NitroMetamask::HybridNitroMetamaskSpec_cxx::fromUnsafe(swiftUnsafePointer);
|
|
44
|
+
return std::make_shared<margelo::nitro::nitrometamask::HybridNitroMetamaskSpecSwift>(swiftPart);
|
|
45
45
|
}
|
|
46
|
-
void* NON_NULL
|
|
47
|
-
std::shared_ptr<margelo::nitro::nitrometamask::
|
|
46
|
+
void* NON_NULL get_std__shared_ptr_HybridNitroMetamaskSpec_(std__shared_ptr_HybridNitroMetamaskSpec_ cppType) {
|
|
47
|
+
std::shared_ptr<margelo::nitro::nitrometamask::HybridNitroMetamaskSpecSwift> swiftWrapper = std::dynamic_pointer_cast<margelo::nitro::nitrometamask::HybridNitroMetamaskSpecSwift>(cppType);
|
|
48
48
|
#ifdef NITRO_DEBUG
|
|
49
49
|
if (swiftWrapper == nullptr) [[unlikely]] {
|
|
50
|
-
throw std::runtime_error("Class \"
|
|
50
|
+
throw std::runtime_error("Class \"HybridNitroMetamaskSpec\" is not implemented in Swift!");
|
|
51
51
|
}
|
|
52
52
|
#endif
|
|
53
|
-
NitroMetamask::
|
|
53
|
+
NitroMetamask::HybridNitroMetamaskSpec_cxx& swiftPart = swiftWrapper->getSwiftPart();
|
|
54
54
|
return swiftPart.toUnsafe();
|
|
55
55
|
}
|
|
56
56
|
|
|
@@ -10,16 +10,16 @@
|
|
|
10
10
|
// Forward declarations of C++ defined types
|
|
11
11
|
// Forward declaration of `ConnectResult` to properly resolve imports.
|
|
12
12
|
namespace margelo::nitro::nitrometamask { struct ConnectResult; }
|
|
13
|
-
// Forward declaration of `
|
|
14
|
-
namespace margelo::nitro::nitrometamask { class
|
|
13
|
+
// Forward declaration of `HybridNitroMetamaskSpec` to properly resolve imports.
|
|
14
|
+
namespace margelo::nitro::nitrometamask { class HybridNitroMetamaskSpec; }
|
|
15
15
|
|
|
16
16
|
// Forward declarations of Swift defined types
|
|
17
|
-
// Forward declaration of `
|
|
18
|
-
namespace NitroMetamask { class
|
|
17
|
+
// Forward declaration of `HybridNitroMetamaskSpec_cxx` to properly resolve imports.
|
|
18
|
+
namespace NitroMetamask { class HybridNitroMetamaskSpec_cxx; }
|
|
19
19
|
|
|
20
20
|
// Include C++ defined types
|
|
21
21
|
#include "ConnectResult.hpp"
|
|
22
|
-
#include "
|
|
22
|
+
#include "HybridNitroMetamaskSpec.hpp"
|
|
23
23
|
#include <NitroModules/Promise.hpp>
|
|
24
24
|
#include <NitroModules/PromiseHolder.hpp>
|
|
25
25
|
#include <NitroModules/Result.hpp>
|
|
@@ -124,17 +124,17 @@ namespace margelo::nitro::nitrometamask::bridge::swift {
|
|
|
124
124
|
return Func_void_std__string_Wrapper(std::move(value));
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
-
// pragma MARK: std::shared_ptr<
|
|
127
|
+
// pragma MARK: std::shared_ptr<HybridNitroMetamaskSpec>
|
|
128
128
|
/**
|
|
129
|
-
* Specialized version of `std::shared_ptr<
|
|
129
|
+
* Specialized version of `std::shared_ptr<HybridNitroMetamaskSpec>`.
|
|
130
130
|
*/
|
|
131
|
-
using
|
|
132
|
-
std::shared_ptr<
|
|
133
|
-
void* NON_NULL
|
|
131
|
+
using std__shared_ptr_HybridNitroMetamaskSpec_ = std::shared_ptr<HybridNitroMetamaskSpec>;
|
|
132
|
+
std::shared_ptr<HybridNitroMetamaskSpec> create_std__shared_ptr_HybridNitroMetamaskSpec_(void* NON_NULL swiftUnsafePointer) noexcept;
|
|
133
|
+
void* NON_NULL get_std__shared_ptr_HybridNitroMetamaskSpec_(std__shared_ptr_HybridNitroMetamaskSpec_ cppType);
|
|
134
134
|
|
|
135
|
-
// pragma MARK: std::weak_ptr<
|
|
136
|
-
using
|
|
137
|
-
inline
|
|
135
|
+
// pragma MARK: std::weak_ptr<HybridNitroMetamaskSpec>
|
|
136
|
+
using std__weak_ptr_HybridNitroMetamaskSpec_ = std::weak_ptr<HybridNitroMetamaskSpec>;
|
|
137
|
+
inline std__weak_ptr_HybridNitroMetamaskSpec_ weakify_std__shared_ptr_HybridNitroMetamaskSpec_(const std::shared_ptr<HybridNitroMetamaskSpec>& strong) noexcept { return strong; }
|
|
138
138
|
|
|
139
139
|
// pragma MARK: Result<std::shared_ptr<Promise<ConnectResult>>>
|
|
140
140
|
using Result_std__shared_ptr_Promise_ConnectResult___ = Result<std::shared_ptr<Promise<ConnectResult>>>;
|