Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: credo ws patch and agent restart #2355

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .yarn/patches/@credo-ts-core-npm-0.5.11-9122d8c9b8.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
diff --git a/build/transport/WsOutboundTransport.js b/build/transport/WsOutboundTransport.js
index ab9df20f9fedc4def4f486b9431ac669e899e609..220157c6082b6c9761e021e611e66510dd9a05fd 100644
--- a/build/transport/WsOutboundTransport.js
+++ b/build/transport/WsOutboundTransport.js
@@ -43,7 +43,16 @@ class WsOutboundTransport {
this.transportTable.forEach((socket) => {
socket.removeEventListener('message', this.handleMessageEvent);
if (socket.readyState !== this.WebSocketClass.CLOSED) {
- stillOpenSocketClosingPromises.push(new Promise((resolve) => socket.once('close', resolve)));
+ stillOpenSocketClosingPromises.push(
+ new Promise((resolve) => {
+ const closeHandler = () => {
+ socket.removeEventListener('close', closeHandler)
+ resolve()
+ }
+
+ socket.addEventListener('close', closeHandler)
+ })
+ );
socket.close();
}
});
13 changes: 13 additions & 0 deletions .yarn/patches/@credo-ts-indy-vdr-npm-0.5.11-ced84362c9.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/build/pool/IndyVdrPool.js b/build/pool/IndyVdrPool.js
index eab13b315dede8a2a7f7f56caa850405cf5f2f47..2109fb8eeae12c490b8233403b4445a5f6e0e465 100644
--- a/build/pool/IndyVdrPool.js
+++ b/build/pool/IndyVdrPool.js
@@ -17,7 +17,7 @@ class IndyVdrPool {
}
connect() {
if (this._pool) {
- throw new error_1.IndyVdrError('Cannot connect to pool, already connected.');
+ return;
}
this._pool = new indy_vdr_shared_1.PoolCreate({
parameters: {
4 changes: 2 additions & 2 deletions app/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ PODS:
- React-jsinspector (0.72.17)
- React-logger (0.72.17):
- glog
- "react-native-attestation (1.0.0-alpha.427+410b3694)":
- "react-native-attestation (1.0.0-alpha.431+af0703e3)":
- RCT-Folly (= 2021.07.22.00)
- React-Core
- react-native-config (1.5.0):
Expand Down Expand Up @@ -946,7 +946,7 @@ SPEC CHECKSUMS:
React-jsiexecutor: 8dc585381e476c3ff2e9468f444c90c4d1d5b874
React-jsinspector: 853b8631b908636bb09ef77cb217376c38a0c8ff
React-logger: 9ca44bb5703bf2355f3c2d2e5e67bfe98ca2dc34
react-native-attestation: 294c885d5f9c956a26562a49a04012b7e15bf3f0
react-native-attestation: 4b14da47333aa16aaef99b35d9ebba93d5bac1d2
react-native-config: 5330c8258265c1e5fdb8c009d2cabd6badd96727
react-native-date-picker: 06a4d96ab525a163c7a90bccd68833d136b0bb13
react-native-encrypted-storage: db300a3f2f0aba1e818417c1c0a6be549038deb7
Expand Down
10 changes: 5 additions & 5 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@
"@formatjs/intl-relativetimeformat": "9.3.1",
"@hyperledger/anoncreds-react-native": "0.2.4",
"@hyperledger/aries-askar-react-native": "0.2.3",
"@hyperledger/aries-bifold-core": "1.0.0-alpha.427",
"@hyperledger/aries-bifold-remote-logs": "1.0.0-alpha.427",
"@hyperledger/aries-bifold-verifier": "1.0.0-alpha.427",
"@hyperledger/aries-oca": "1.0.0-alpha.427",
"@hyperledger/aries-react-native-attestation": "1.0.0-alpha.427",
"@hyperledger/aries-bifold-core": "1.0.0-alpha.431",
"@hyperledger/aries-bifold-remote-logs": "1.0.0-alpha.431",
"@hyperledger/aries-bifold-verifier": "1.0.0-alpha.431",
"@hyperledger/aries-oca": "1.0.0-alpha.431",
"@hyperledger/aries-react-native-attestation": "1.0.0-alpha.431",
"@hyperledger/indy-vdr-react-native": "0.2.2",
"@hyperledger/indy-vdr-shared": "0.2.2",
"@react-native-async-storage/async-storage": "1.15.11",
Expand Down
57 changes: 47 additions & 10 deletions app/src/hooks/initialize-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const loadCachedLedgers = async (): Promise<IndyVdrPoolConfig[] | undefined> =>
}

const useInitializeBCAgent = () => {
const { setAgent } = useAgent()
const { agent, setAgent } = useAgent()
const [store, dispatch] = useStore<BCState>()
const { walletSecret } = useAuth()
const [logger, indyLedgers, attestationMonitor, credDefs, schemas] = useServices([
Expand All @@ -42,6 +42,35 @@ const useInitializeBCAgent = () => {
TOKENS.CACHE_SCHEMAS,
])

const refreshAttestationMonitor = useCallback((agent: Agent) => {
attestationMonitor?.stop()
attestationMonitor?.start(agent)
}, [attestationMonitor])

const restartExistingAgent = useCallback(async () => {
// if the agent is initialized, it was not a clean shutdown and should be replaced, not restarted
if (!walletSecret?.id || !walletSecret.key || !agent || agent.isInitialized) {
return
}

logger.info('Agent already created, restarting...')
try {
await agent.wallet.open({
id: walletSecret.id,
key: walletSecret.key,
})
await agent.initialize()
} catch {
// if the existing agents wallet cannot be opened or initialize() fails it was
// again not a clean shutdown and the agent should be replaced, not restarted
logger.error('Failed to restart existing agent, skipping agent restart')
return
}

logger.info('Successfully restarted existing agent')
return agent
}, [walletSecret, agent, logger])

const createNewAgent = useCallback(
async (ledgers: IndyVdrPoolConfig[]): Promise<Agent | undefined> => {
if (!walletSecret?.id || !walletSecret.key) {
Expand Down Expand Up @@ -168,12 +197,20 @@ const useInitializeBCAgent = () => {
return
}

const existingAgent = await restartExistingAgent()
if (existingAgent) {
refreshAttestationMonitor(existingAgent)
setAgent(existingAgent)
return existingAgent
}

const cachedLedgers = await loadCachedLedgers()
const ledgers = cachedLedgers ?? indyLedgers

const newAgent = await createNewAgent(ledgers)
if (!newAgent) {
return
logger.error('Failed to create a new agent')
bryce-mcmath marked this conversation as resolved.
Show resolved Hide resolved
throw new Error('Failed to create a a new agent')
}

logger.info('Migrating agent if required...')
Expand All @@ -187,31 +224,31 @@ const useInitializeBCAgent = () => {

logger.info('Creating link secret if required...')
await createLinkSecretIfRequired(newAgent)

if (store.preferences.usePushNotifications) {
logger.info('Activating push notifications...')
activate(newAgent)
}

// In case the old attestationMonitor is still active, stop it and start a new one
logger.info('Starting attestation monitor...')
attestationMonitor?.stop()
attestationMonitor?.start(newAgent)
refreshAttestationMonitor(newAgent)

logger.info('Setting new agent...')
setAgent(newAgent)

return newAgent
}, [
walletSecret,
restartExistingAgent,
setAgent,
indyLedgers,
createNewAgent,
logger,
migrateIfRequired,
warmUpCache,
store.preferences.usePushNotifications,
walletSecret,
logger,
indyLedgers,
attestationMonitor,
refreshAttestationMonitor,
])

return { initializeAgent }
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
"react-native": "0.72.17",
"react-i18next": "11.18.6",
"react-native-vision-camera": "4.3.1",
"@credo-ts/core": "patch:@credo-ts/core@npm%3A0.5.11#~/.yarn/patches/@credo-ts-core-npm-0.5.11-9122d8c9b8.patch",
"@credo-ts/indy-vdr": "patch:@credo-ts/indy-vdr@npm%3A0.5.11#~/.yarn/patches/@credo-ts-indy-vdr-npm-0.5.11-ced84362c9.patch",
"@credo-ts/react-hooks": "patch:@credo-ts/react-hooks@npm%3A0.6.0#./.yarn/patches/@credo-ts-react-hooks-npm-0.6.0-3c59ce13d2.patch",
"@hyperledger/indy-vdr-shared@npm:0.2.2": "patch:@hyperledger/indy-vdr-shared@npm%3A0.2.2#~/.yarn/patches/@hyperledger-indy-vdr-shared-npm-0.2.2-b989282fc6.patch",
"@hyperledger/indy-vdr-react-native": "patch:@hyperledger/indy-vdr-react-native@npm%3A0.2.2#~/.yarn/patches/@hyperledger-indy-vdr-react-native-npm-0.2.2-627d424b96.patch"
Expand Down
114 changes: 87 additions & 27 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2364,7 +2364,7 @@ __metadata:
languageName: node
linkType: hard

"@credo-ts/core@npm:0.5.11, @credo-ts/core@npm:^0.5.11":
"@credo-ts/core@npm:0.5.11":
version: 0.5.11
resolution: "@credo-ts/core@npm:0.5.11"
dependencies:
Expand Down Expand Up @@ -2412,6 +2412,54 @@ __metadata:
languageName: node
linkType: hard

"@credo-ts/core@patch:@credo-ts/core@npm%3A0.5.11#~/.yarn/patches/@credo-ts-core-npm-0.5.11-9122d8c9b8.patch":
version: 0.5.11
resolution: "@credo-ts/core@patch:@credo-ts/core@npm%3A0.5.11#~/.yarn/patches/@credo-ts-core-npm-0.5.11-9122d8c9b8.patch::version=0.5.11&hash=a9d8aa"
dependencies:
"@digitalcredentials/jsonld": "npm:^6.0.0"
"@digitalcredentials/jsonld-signatures": "npm:^9.4.0"
"@digitalcredentials/vc": "npm:^6.0.1"
"@multiformats/base-x": "npm:^4.0.1"
"@noble/hashes": "npm:^1.4.0"
"@peculiar/asn1-ecc": "npm:^2.3.8"
"@peculiar/asn1-schema": "npm:^2.3.8"
"@peculiar/asn1-x509": "npm:^2.3.8"
"@peculiar/x509": "npm:^1.11.0"
"@sd-jwt/core": "npm:^0.7.0"
"@sd-jwt/decode": "npm:^0.7.0"
"@sd-jwt/jwt-status-list": "npm:^0.7.0"
"@sd-jwt/sd-jwt-vc": "npm:^0.7.0"
"@sd-jwt/types": "npm:^0.7.0"
"@sd-jwt/utils": "npm:^0.7.0"
"@sphereon/pex": "npm:^3.3.2"
"@sphereon/pex-models": "npm:^2.2.4"
"@sphereon/ssi-types": "npm:^0.28.0"
"@stablelib/ed25519": "npm:^1.0.2"
"@types/ws": "npm:^8.5.4"
abort-controller: "npm:^3.0.0"
big-integer: "npm:^1.6.51"
borc: "npm:^3.0.0"
buffer: "npm:^6.0.3"
class-transformer: "npm:0.5.1"
class-validator: "npm:0.14.1"
did-resolver: "npm:^4.1.0"
jsonpath: "npm:^1.1.1"
lru_map: "npm:^0.4.1"
luxon: "npm:^3.3.0"
make-error: "npm:^1.3.6"
object-inspect: "npm:^1.10.3"
query-string: "npm:^7.0.1"
reflect-metadata: "npm:^0.1.13"
rxjs: "npm:^7.8.0"
tsyringe: "npm:^4.8.0"
uuid: "npm:^9.0.0"
varint: "npm:^6.0.0"
web-did-resolver: "npm:^2.0.21"
webcrypto-core: "npm:^1.8.0"
checksum: 6f276e608334048c4fd5cc57558ac16acfc7dee6fba727286808a7695a973ac9b1284b7c43a120679857827c5c783e02428c07a7ba7b499be6eefca4722b646a
languageName: node
linkType: hard

"@credo-ts/drpc@npm:0.5.11":
version: 0.5.11
resolution: "@credo-ts/drpc@npm:0.5.11"
Expand Down Expand Up @@ -2449,6 +2497,18 @@ __metadata:
languageName: node
linkType: hard

"@credo-ts/indy-vdr@patch:@credo-ts/indy-vdr@npm%3A0.5.11#~/.yarn/patches/@credo-ts-indy-vdr-npm-0.5.11-ced84362c9.patch":
version: 0.5.11
resolution: "@credo-ts/indy-vdr@patch:@credo-ts/indy-vdr@npm%3A0.5.11#~/.yarn/patches/@credo-ts-indy-vdr-npm-0.5.11-ced84362c9.patch::version=0.5.11&hash=c42b94"
dependencies:
"@credo-ts/anoncreds": "npm:0.5.11"
"@credo-ts/core": "npm:0.5.11"
peerDependencies:
"@hyperledger/indy-vdr-shared": ^0.2.2
checksum: 769af09f707e7a7e076a3c5d928b697bff29b26a62d4b763f1a96f4133aff06e16288bcb1832a55fe6e18902ccbee630980f89d1ef39cc2b595f4104f184e6d1
languageName: node
linkType: hard

"@credo-ts/node@npm:0.5.11":
version: 0.5.11
resolution: "@credo-ts/node@npm:0.5.11"
Expand Down Expand Up @@ -3253,9 +3313,9 @@ __metadata:
languageName: node
linkType: hard

"@hyperledger/aries-bifold-core@npm:1.0.0-alpha.427, @hyperledger/aries-bifold-core@npm:^1.0.0-alpha.427+410b3694":
version: 1.0.0-alpha.427
resolution: "@hyperledger/aries-bifold-core@npm:1.0.0-alpha.427"
"@hyperledger/aries-bifold-core@npm:1.0.0-alpha.431, @hyperledger/aries-bifold-core@npm:^1.0.0-alpha.431+af0703e3":
version: 1.0.0-alpha.431
resolution: "@hyperledger/aries-bifold-core@npm:1.0.0-alpha.431"
peerDependencies:
"@credo-ts/anoncreds": 0.5.11
"@credo-ts/askar": 0.5.11
Expand Down Expand Up @@ -3331,16 +3391,16 @@ __metadata:
uuid: ^9.0.0
bin:
bifold: bin/bifold
checksum: b55ac8aca9415f4f31c5d1784d6b77c4ed7068ee6b10c463e87e60dec3df6edf8a8c94e068c8cb4adc496e1a4f68864f4f7c2174ecd55e62fbd1c8b5190b168e
checksum: 91480dd2532f439645276a782581b965102fa47b152da8204945f1dd6994033418943a2a5a6c6a21a5bd50d040ab05a9a4684da65f10f7d852e7aaed893ce35c
languageName: node
linkType: hard

"@hyperledger/aries-bifold-remote-logs@npm:1.0.0-alpha.427":
version: 1.0.0-alpha.427
resolution: "@hyperledger/aries-bifold-remote-logs@npm:1.0.0-alpha.427"
"@hyperledger/aries-bifold-remote-logs@npm:1.0.0-alpha.431":
version: 1.0.0-alpha.431
resolution: "@hyperledger/aries-bifold-remote-logs@npm:1.0.0-alpha.431"
dependencies:
"@credo-ts/core": "npm:0.5.11"
"@hyperledger/aries-bifold-core": "npm:^1.0.0-alpha.427+410b3694"
"@hyperledger/aries-bifold-core": "npm:^1.0.0-alpha.431+af0703e3"
axios: "npm:^1.4.0"
buffer: "npm:^6.0.3"
react: "npm:18.2.0"
Expand All @@ -3353,43 +3413,43 @@ __metadata:
react: ^18.2.0
react-native: ^0.72.17
react-native-logs: ^5.1.0
checksum: b3f80665fa827e9f4e8e05c6278a7f1205d8eb9e2aac020f5391a3d6785cd6b8212adde3e26904b087bf86cc3a260844a44ca3c4e26ddafd1a7ba4a6464af1ff
checksum: 8e1ab0253b3bff81085825c38117081c4b2690f4e616ea085a630a013d9cc01c3149a22ba4bf788c5e29588f2a14c04bf4c36a799296ed7529e75b6cda42bd54
languageName: node
linkType: hard

"@hyperledger/aries-bifold-verifier@npm:1.0.0-alpha.427":
version: 1.0.0-alpha.427
resolution: "@hyperledger/aries-bifold-verifier@npm:1.0.0-alpha.427"
"@hyperledger/aries-bifold-verifier@npm:1.0.0-alpha.431":
version: 1.0.0-alpha.431
resolution: "@hyperledger/aries-bifold-verifier@npm:1.0.0-alpha.431"
peerDependencies:
"@credo-ts/anoncreds": 0.5.11
"@credo-ts/core": 0.5.11
"@credo-ts/react-hooks": ^0.6.0
"@hyperledger/anoncreds-shared": 0.2.4
react: ^18.2.0
checksum: 1d747a18de992a378394166d35d434fb91a37c7a9883372cb6a136ba648dd646424e64b10b9f7e90344da799e1f218004673651726a8a01a756e1d36329a8b7d
checksum: 159306418b46d7620e37e3522b7f7b30e89c6edebfb914c5c82335abbb5c038782abb12348f8ce7728ab403a352150464859aad4d4efe67770d40e8c325124d0
languageName: node
linkType: hard

"@hyperledger/aries-oca@npm:1.0.0-alpha.427":
version: 1.0.0-alpha.427
resolution: "@hyperledger/aries-oca@npm:1.0.0-alpha.427"
"@hyperledger/aries-oca@npm:1.0.0-alpha.431":
version: 1.0.0-alpha.431
resolution: "@hyperledger/aries-oca@npm:1.0.0-alpha.431"
dependencies:
"@credo-ts/anoncreds": "npm:0.5.11"
"@credo-ts/core": "npm:0.5.11"
axios: "npm:^1.4.0"
lodash.startcase: "npm:^4.4.0"
react-native-fs: "npm:^2.16.6"
checksum: 8e37eb50198b4b9119046f428d6511bd89140f2d32c2639d4e5e6e212db9d2640b74d833bde08ceb682c17877bd12fd04188db4340131ec206fdf3f8f2c9579f
checksum: a2cac5b21c334deccbd4c3a7211189cdb6ea3136c1635be2cdc5076909cf994b14bbee439d33cafb8d72c6637bd1122c715fb6189cbeaa1957192c53a78c7d53
languageName: node
linkType: hard

"@hyperledger/aries-react-native-attestation@npm:1.0.0-alpha.427":
version: 1.0.0-alpha.427
resolution: "@hyperledger/aries-react-native-attestation@npm:1.0.0-alpha.427"
"@hyperledger/aries-react-native-attestation@npm:1.0.0-alpha.431":
version: 1.0.0-alpha.431
resolution: "@hyperledger/aries-react-native-attestation@npm:1.0.0-alpha.431"
peerDependencies:
react: "*"
react-native: "*"
checksum: b401754473915292b7a6674d03154470cc2b26d1e8692975083bcccdfd1a4cf55bad1046da8e9ed31ab68d685d79d4dd06963d0209b30b8b1e1f9b4eabd83366
checksum: edd70b4e524efa0853c8c2a874e43d7fa8ef753307466d0cc87767b3bb686cd50d5f93b2218fcd656e5370801b11afaa4527b19a1442a086b6b9ad16b2d08b84
languageName: node
linkType: hard

Expand Down Expand Up @@ -8303,11 +8363,11 @@ __metadata:
"@formatjs/intl-relativetimeformat": "npm:9.3.1"
"@hyperledger/anoncreds-react-native": "npm:0.2.4"
"@hyperledger/aries-askar-react-native": "npm:0.2.3"
"@hyperledger/aries-bifold-core": "npm:1.0.0-alpha.427"
"@hyperledger/aries-bifold-remote-logs": "npm:1.0.0-alpha.427"
"@hyperledger/aries-bifold-verifier": "npm:1.0.0-alpha.427"
"@hyperledger/aries-oca": "npm:1.0.0-alpha.427"
"@hyperledger/aries-react-native-attestation": "npm:1.0.0-alpha.427"
"@hyperledger/aries-bifold-core": "npm:1.0.0-alpha.431"
"@hyperledger/aries-bifold-remote-logs": "npm:1.0.0-alpha.431"
"@hyperledger/aries-bifold-verifier": "npm:1.0.0-alpha.431"
"@hyperledger/aries-oca": "npm:1.0.0-alpha.431"
"@hyperledger/aries-react-native-attestation": "npm:1.0.0-alpha.431"
"@hyperledger/indy-vdr-react-native": "npm:0.2.2"
"@hyperledger/indy-vdr-shared": "npm:0.2.2"
"@react-native-async-storage/async-storage": "npm:1.15.11"
Expand Down
Loading