From dec947f686c4d4763c15684800fa35de74e83c62 Mon Sep 17 00:00:00 2001
From: Jerry Johns <johnsj@google.com>
Date: Tue, 26 Jul 2022 08:07:06 -0700
Subject: [PATCH] Replace `PeerId` -> `ScopedNodeId` where applicable. (#20896)

* Replace PeerId -> ScopedNodeId where applicable.

Lots of places were still using PeerId when they shouldn't be.

* Review feedback and build fixes

* Darwin build fix
---
 .../esp32/main/include/ShellCommands.h        |  7 +--
 .../esp32/main/include/ShellCommands.h        |  7 +--
 .../commands/clusters/ModelCommand.cpp        |  2 +-
 .../commands/clusters/ModelCommand.h          |  2 +-
 .../commands/pairing/CloseSessionCommand.cpp  |  2 +-
 .../commands/pairing/CloseSessionCommand.h    |  2 +-
 .../chip-tool/commands/tests/TestCommand.cpp  |  2 +-
 .../chip-tool/commands/tests/TestCommand.h    |  2 +-
 examples/platform/linux/CommissionerMain.cpp  |  4 +-
 .../commands/clusters/ModelCommand.cpp        | 14 ++----
 .../include/TargetVideoPlayerInfo.h           |  2 +-
 .../src/TargetVideoPlayerInfo.cpp             | 14 ++----
 src/app/CASEClient.cpp                        |  8 +--
 src/app/CASEClient.h                          |  3 +-
 src/app/CASESessionManager.cpp                | 12 ++---
 src/app/CASESessionManager.h                  |  8 +--
 src/app/OperationalDeviceProxy.cpp            | 44 ++++++++---------
 src/app/OperationalDeviceProxy.h              | 24 +++------
 src/app/OperationalDeviceProxyPool.h          |  8 +--
 src/app/clusters/bindings/BindingManager.cpp  | 49 +++++++------------
 src/app/clusters/bindings/BindingManager.h    |  6 +--
 .../bindings/PendingNotificationMap.cpp       |  9 ++--
 .../bindings/PendingNotificationMap.h         |  6 +--
 .../ota-requestor/DefaultOTARequestor.cpp     | 28 ++---------
 .../ota-requestor/DefaultOTARequestor.h       |  8 ++-
 src/app/tests/TestPendingNotificationMap.cpp  | 22 ++++-----
 src/controller/CHIPDeviceController.cpp       | 21 ++++----
 src/controller/CHIPDeviceController.h         | 15 +++---
 src/controller/CommissioningWindowOpener.cpp  |  2 +-
 src/controller/CommissioningWindowOpener.h    |  2 +-
 src/controller/java/AndroidCallbacks.cpp      |  2 +-
 src/controller/java/AndroidCallbacks.h        |  2 +-
 .../java/CHIPDeviceController-JNI.cpp         |  6 +--
 .../ChipDeviceController-ScriptBinding.cpp    | 11 ++---
 .../CHIP/MTRDeviceConnectionBridge.h          |  2 +-
 .../CHIP/MTRDeviceConnectionBridge.mm         |  2 +-
 36 files changed, 148 insertions(+), 212 deletions(-)

diff --git a/examples/all-clusters-app/esp32/main/include/ShellCommands.h b/examples/all-clusters-app/esp32/main/include/ShellCommands.h
index 3e4e8536cee962..832039dd90358b 100644
--- a/examples/all-clusters-app/esp32/main/include/ShellCommands.h
+++ b/examples/all-clusters-app/esp32/main/include/ShellCommands.h
@@ -140,7 +140,7 @@ class CASECommands
         GetInstance().SetOnConnecting(false);
     }
 
-    static void OnConnectionFailure(void * context, PeerId peerId, CHIP_ERROR error)
+    static void OnConnectionFailure(void * context, const ScopedNodeId & peerId, CHIP_ERROR error)
     {
         streamer_printf(streamer_get(), "Establish CASESession Failure!\r\n");
         GetInstance().SetOnConnecting(false);
@@ -156,8 +156,9 @@ class CASECommands
             ChipLogError(SecureChannel, "Can't get the CASESessionManager");
             return;
         }
-        caseSessionManager->FindOrEstablishSession(caseCommand->GetFabricInfo()->GetPeerIdForNode(caseCommand->GetNodeId()),
-                                                   &sOnConnectedCallback, &sOnConnectionFailureCallback);
+        caseSessionManager->FindOrEstablishSession(
+            ScopedNodeId(caseCommand->GetNodeId(), caseCommand->GetFabricInfo()->GetFabricIndex()), &sOnConnectedCallback,
+            &sOnConnectionFailureCallback);
     }
 
     static CHIP_ERROR ConnectToNodeHandler(int argc, char ** argv)
diff --git a/examples/all-clusters-minimal-app/esp32/main/include/ShellCommands.h b/examples/all-clusters-minimal-app/esp32/main/include/ShellCommands.h
index 3e4e8536cee962..832039dd90358b 100644
--- a/examples/all-clusters-minimal-app/esp32/main/include/ShellCommands.h
+++ b/examples/all-clusters-minimal-app/esp32/main/include/ShellCommands.h
@@ -140,7 +140,7 @@ class CASECommands
         GetInstance().SetOnConnecting(false);
     }
 
-    static void OnConnectionFailure(void * context, PeerId peerId, CHIP_ERROR error)
+    static void OnConnectionFailure(void * context, const ScopedNodeId & peerId, CHIP_ERROR error)
     {
         streamer_printf(streamer_get(), "Establish CASESession Failure!\r\n");
         GetInstance().SetOnConnecting(false);
@@ -156,8 +156,9 @@ class CASECommands
             ChipLogError(SecureChannel, "Can't get the CASESessionManager");
             return;
         }
-        caseSessionManager->FindOrEstablishSession(caseCommand->GetFabricInfo()->GetPeerIdForNode(caseCommand->GetNodeId()),
-                                                   &sOnConnectedCallback, &sOnConnectionFailureCallback);
+        caseSessionManager->FindOrEstablishSession(
+            ScopedNodeId(caseCommand->GetNodeId(), caseCommand->GetFabricInfo()->GetFabricIndex()), &sOnConnectedCallback,
+            &sOnConnectionFailureCallback);
     }
 
     static CHIP_ERROR ConnectToNodeHandler(int argc, char ** argv)
diff --git a/examples/chip-tool/commands/clusters/ModelCommand.cpp b/examples/chip-tool/commands/clusters/ModelCommand.cpp
index fd255abfe204b0..c67cebb1491fe0 100644
--- a/examples/chip-tool/commands/clusters/ModelCommand.cpp
+++ b/examples/chip-tool/commands/clusters/ModelCommand.cpp
@@ -55,7 +55,7 @@ void ModelCommand::OnDeviceConnectedFn(void * context, chip::OperationalDevicePr
     VerifyOrReturn(CHIP_NO_ERROR == err, command->SetCommandExitStatus(err));
 }
 
-void ModelCommand::OnDeviceConnectionFailureFn(void * context, PeerId peerId, CHIP_ERROR err)
+void ModelCommand::OnDeviceConnectionFailureFn(void * context, const chip::ScopedNodeId & peerId, CHIP_ERROR err)
 {
     LogErrorOnFailure(err);
 
diff --git a/examples/chip-tool/commands/clusters/ModelCommand.h b/examples/chip-tool/commands/clusters/ModelCommand.h
index 4a0c2c08f5d469..d6581235863160 100644
--- a/examples/chip-tool/commands/clusters/ModelCommand.h
+++ b/examples/chip-tool/commands/clusters/ModelCommand.h
@@ -70,7 +70,7 @@ class ModelCommand : public CHIPCommand
     std::vector<chip::EndpointId> mEndPointId;
 
     static void OnDeviceConnectedFn(void * context, chip::OperationalDeviceProxy * device);
-    static void OnDeviceConnectionFailureFn(void * context, PeerId peerId, CHIP_ERROR error);
+    static void OnDeviceConnectionFailureFn(void * context, const chip::ScopedNodeId & peerId, CHIP_ERROR error);
 
     chip::Callback::Callback<chip::OnDeviceConnected> mOnDeviceConnectedCallback;
     chip::Callback::Callback<chip::OnDeviceConnectionFailure> mOnDeviceConnectionFailureCallback;
diff --git a/examples/chip-tool/commands/pairing/CloseSessionCommand.cpp b/examples/chip-tool/commands/pairing/CloseSessionCommand.cpp
index b30d0accae1639..210164770a6ff7 100644
--- a/examples/chip-tool/commands/pairing/CloseSessionCommand.cpp
+++ b/examples/chip-tool/commands/pairing/CloseSessionCommand.cpp
@@ -78,7 +78,7 @@ void CloseSessionCommand::OnDeviceConnectedFn(void * context, OperationalDeviceP
     VerifyOrReturn(CHIP_NO_ERROR == err, command->SetCommandExitStatus(err));
 }
 
-void CloseSessionCommand::OnDeviceConnectionFailureFn(void * context, PeerId peerId, CHIP_ERROR err)
+void CloseSessionCommand::OnDeviceConnectionFailureFn(void * context, const chip::ScopedNodeId & peerId, CHIP_ERROR err)
 {
     LogErrorOnFailure(err);
 
diff --git a/examples/chip-tool/commands/pairing/CloseSessionCommand.h b/examples/chip-tool/commands/pairing/CloseSessionCommand.h
index 782e334ebfe74a..270c45210f4ebe 100644
--- a/examples/chip-tool/commands/pairing/CloseSessionCommand.h
+++ b/examples/chip-tool/commands/pairing/CloseSessionCommand.h
@@ -47,7 +47,7 @@ class CloseSessionCommand : public CHIPCommand
     chip::Optional<uint16_t> mTimeoutSecs;
 
     static void OnDeviceConnectedFn(void * context, chip::OperationalDeviceProxy * device);
-    static void OnDeviceConnectionFailureFn(void * context, PeerId peerId, CHIP_ERROR error);
+    static void OnDeviceConnectionFailureFn(void * context, const chip::ScopedNodeId & peerId, CHIP_ERROR error);
 
     // Try to send the action CloseSession status report.
     CHIP_ERROR CloseSession(chip::DeviceProxy * device);
diff --git a/examples/chip-tool/commands/tests/TestCommand.cpp b/examples/chip-tool/commands/tests/TestCommand.cpp
index 75c4bd34482578..6de48bd810ac79 100644
--- a/examples/chip-tool/commands/tests/TestCommand.cpp
+++ b/examples/chip-tool/commands/tests/TestCommand.cpp
@@ -61,7 +61,7 @@ void TestCommand::OnDeviceConnectedFn(void * context, chip::OperationalDevicePro
     LogErrorOnFailure(command->ContinueOnChipMainThread(CHIP_NO_ERROR));
 }
 
-void TestCommand::OnDeviceConnectionFailureFn(void * context, PeerId peerId, CHIP_ERROR error)
+void TestCommand::OnDeviceConnectionFailureFn(void * context, const chip::ScopedNodeId & peerId, CHIP_ERROR error)
 {
     ChipLogProgress(chipTool, " **** Test Setup: Device Connection Failure [deviceId=%" PRIu64 ". Error %" CHIP_ERROR_FORMAT "\n]",
                     peerId.GetNodeId(), error.Format());
diff --git a/examples/chip-tool/commands/tests/TestCommand.h b/examples/chip-tool/commands/tests/TestCommand.h
index 11bc4041304a37..e35b64df24b7a3 100644
--- a/examples/chip-tool/commands/tests/TestCommand.h
+++ b/examples/chip-tool/commands/tests/TestCommand.h
@@ -71,7 +71,7 @@ class TestCommand : public TestRunner,
     void OnResponse(const chip::app::StatusIB & status, chip::TLV::TLVReader * data) override{};
 
     static void OnDeviceConnectedFn(void * context, chip::OperationalDeviceProxy * device);
-    static void OnDeviceConnectionFailureFn(void * context, PeerId peerId, CHIP_ERROR error);
+    static void OnDeviceConnectionFailureFn(void * context, const chip::ScopedNodeId & peerId, CHIP_ERROR error);
 
     CHIP_ERROR ContinueOnChipMainThread(CHIP_ERROR err) override;
 
diff --git a/examples/platform/linux/CommissionerMain.cpp b/examples/platform/linux/CommissionerMain.cpp
index 18b86e1051fe99..d70ead1203cfdf 100644
--- a/examples/platform/linux/CommissionerMain.cpp
+++ b/examples/platform/linux/CommissionerMain.cpp
@@ -234,7 +234,7 @@ class PairingCommand : public Controller::DevicePairingDelegate
 private:
 #if CHIP_DEVICE_CONFIG_APP_PLATFORM_ENABLED
     static void OnDeviceConnectedFn(void * context, chip::OperationalDeviceProxy * device);
-    static void OnDeviceConnectionFailureFn(void * context, PeerId peerId, CHIP_ERROR error);
+    static void OnDeviceConnectionFailureFn(void * context, const ScopedNodeId & peerId, CHIP_ERROR error);
 
     chip::Callback::Callback<chip::OnDeviceConnected> mOnDeviceConnectedCallback;
     chip::Callback::Callback<chip::OnDeviceConnectionFailure> mOnDeviceConnectionFailureCallback;
@@ -333,7 +333,7 @@ void PairingCommand::OnDeviceConnectedFn(void * context, chip::OperationalDevice
     }
 }
 
-void PairingCommand::OnDeviceConnectionFailureFn(void * context, PeerId peerId, CHIP_ERROR err)
+void PairingCommand::OnDeviceConnectionFailureFn(void * context, const ScopedNodeId & peerId, CHIP_ERROR err)
 {
     ChipLogProgress(Controller, "OnDeviceConnectionFailureFn - attempt to get OperationalDeviceProxy failed");
     CommissionerDiscoveryController * cdc = GetCommissionerDiscoveryController();
diff --git a/examples/tv-casting-app/tv-casting-common/commands/clusters/ModelCommand.cpp b/examples/tv-casting-app/tv-casting-common/commands/clusters/ModelCommand.cpp
index 2953c4ba2a91f1..5982c67f8e41ae 100644
--- a/examples/tv-casting-app/tv-casting-common/commands/clusters/ModelCommand.cpp
+++ b/examples/tv-casting-app/tv-casting-common/commands/clusters/ModelCommand.cpp
@@ -47,16 +47,8 @@ CHIP_ERROR ModelCommand::RunCommand()
         return SendGroupCommand(GroupIdFromNodeId(mDestinationId), fabricIndex);
     }
 
-    Server * server           = &(chip::Server::GetInstance());
-    const FabricInfo * fabric = server->GetFabricTable().FindFabricWithIndex(fabricIndex);
-    if (fabric == nullptr)
-    {
-        ChipLogError(AppServer, "Did not find fabric for index %d", fabricIndex);
-        return CHIP_ERROR_INVALID_FABRIC_INDEX;
-    }
-
-    PeerId peerID = fabric->GetPeerIdForNode(mDestinationId);
-    server->GetCASESessionManager()->FindOrEstablishSession(peerID, &mOnDeviceConnectedCallback,
+    Server * server = &(chip::Server::GetInstance());
+    server->GetCASESessionManager()->FindOrEstablishSession(ScopedNodeId(mDestinationId, fabricIndex), &mOnDeviceConnectedCallback,
                                                             &mOnDeviceConnectionFailureCallback);
     return CHIP_NO_ERROR;
 }
@@ -71,7 +63,7 @@ void ModelCommand::OnDeviceConnectedFn(void * context, OperationalDeviceProxy *
     VerifyOrReturn(CHIP_NO_ERROR == err, command->SetCommandExitStatus(err));
 }
 
-void ModelCommand::OnDeviceConnectionFailureFn(void * context, PeerId peerId, CHIP_ERROR err)
+void ModelCommand::OnDeviceConnectionFailureFn(void * context, const ScopedNodeId & peerId, CHIP_ERROR err)
 {
     ChipLogProgress(chipTool, "ModelCommand::OnDeviceConnectionFailureFn");
     LogErrorOnFailure(err);
diff --git a/examples/tv-casting-app/tv-casting-common/include/TargetVideoPlayerInfo.h b/examples/tv-casting-app/tv-casting-common/include/TargetVideoPlayerInfo.h
index 1db14a7bfc4e9e..1e2265d20dd8b3 100644
--- a/examples/tv-casting-app/tv-casting-common/include/TargetVideoPlayerInfo.h
+++ b/examples/tv-casting-app/tv-casting-common/include/TargetVideoPlayerInfo.h
@@ -49,7 +49,7 @@ class TargetVideoPlayerInfo
         ChipLogProgress(AppServer, "HandleDeviceConnected created an instance of OperationalDeviceProxy");
     }
 
-    static void HandleDeviceConnectionFailure(void * context, chip::PeerId peerId, CHIP_ERROR error)
+    static void HandleDeviceConnectionFailure(void * context, const chip::ScopedNodeId & peerId, CHIP_ERROR error)
     {
         TargetVideoPlayerInfo * _this  = static_cast<TargetVideoPlayerInfo *>(context);
         _this->mOperationalDeviceProxy = nullptr;
diff --git a/examples/tv-casting-app/tv-casting-common/src/TargetVideoPlayerInfo.cpp b/examples/tv-casting-app/tv-casting-common/src/TargetVideoPlayerInfo.cpp
index 9a08e65a13fabe..546c68681b9fb3 100644
--- a/examples/tv-casting-app/tv-casting-common/src/TargetVideoPlayerInfo.cpp
+++ b/examples/tv-casting-app/tv-casting-common/src/TargetVideoPlayerInfo.cpp
@@ -32,17 +32,9 @@ CHIP_ERROR TargetVideoPlayerInfo::Initialize(NodeId nodeId, FabricIndex fabricIn
         endpointInfo.Reset();
     }
 
-    Server * server           = &(chip::Server::GetInstance());
-    const FabricInfo * fabric = server->GetFabricTable().FindFabricWithIndex(fabricIndex);
-    if (fabric == nullptr)
-    {
-        ChipLogError(AppServer, "Did not find fabric for index %d", fabricIndex);
-        return CHIP_ERROR_INVALID_FABRIC_INDEX;
-    }
-
-    PeerId peerID = fabric->GetPeerIdForNode(nodeId);
-
-    server->GetCASESessionManager()->FindOrEstablishSession(peerID, &mOnConnectedCallback, &mOnConnectionFailureCallback);
+    Server * server = &(chip::Server::GetInstance());
+    server->GetCASESessionManager()->FindOrEstablishSession(ScopedNodeId(nodeId, fabricIndex), &mOnConnectedCallback,
+                                                            &mOnConnectionFailureCallback);
 
     if (mOperationalDeviceProxy == nullptr)
     {
diff --git a/src/app/CASEClient.cpp b/src/app/CASEClient.cpp
index 31564a43d904d4..f514b3aa4c089c 100644
--- a/src/app/CASEClient.cpp
+++ b/src/app/CASEClient.cpp
@@ -26,7 +26,7 @@ void CASEClient::SetRemoteMRPIntervals(const ReliableMessageProtocolConfig & rem
     mCASESession.SetRemoteMRPConfig(remoteMRPConfig);
 }
 
-CHIP_ERROR CASEClient::EstablishSession(PeerId peer, const Transport::PeerAddress & peerAddress,
+CHIP_ERROR CASEClient::EstablishSession(const ScopedNodeId & peer, const Transport::PeerAddress & peerAddress,
                                         const ReliableMessageProtocolConfig & remoteMRPConfig,
                                         SessionEstablishmentDelegate * delegate)
 {
@@ -46,9 +46,9 @@ CHIP_ERROR CASEClient::EstablishSession(PeerId peer, const Transport::PeerAddres
     VerifyOrReturnError(exchange != nullptr, CHIP_ERROR_INTERNAL);
 
     mCASESession.SetGroupDataProvider(mInitParams.groupDataProvider);
-    ReturnErrorOnFailure(mCASESession.EstablishSession(
-        *mInitParams.sessionManager, mInitParams.fabricTable, ScopedNodeId{ peer.GetNodeId(), mInitParams.fabricIndex }, exchange,
-        mInitParams.sessionResumptionStorage, mInitParams.certificateValidityPolicy, delegate, mInitParams.mrpLocalConfig));
+    ReturnErrorOnFailure(mCASESession.EstablishSession(*mInitParams.sessionManager, mInitParams.fabricTable, peer, exchange,
+                                                       mInitParams.sessionResumptionStorage, mInitParams.certificateValidityPolicy,
+                                                       delegate, mInitParams.mrpLocalConfig));
 
     return CHIP_NO_ERROR;
 }
diff --git a/src/app/CASEClient.h b/src/app/CASEClient.h
index 42fd3192343e5e..33dfad16bab0cf 100644
--- a/src/app/CASEClient.h
+++ b/src/app/CASEClient.h
@@ -33,7 +33,6 @@ struct CASEClientInitParams
     Credentials::CertificateValidityPolicy * certificateValidityPolicy = nullptr;
     Messaging::ExchangeManager * exchangeMgr                           = nullptr;
     FabricTable * fabricTable                                          = nullptr;
-    FabricIndex fabricIndex                                            = kUndefinedFabricIndex;
     Credentials::GroupDataProvider * groupDataProvider                 = nullptr;
 
     Optional<ReliableMessageProtocolConfig> mrpLocalConfig = Optional<ReliableMessageProtocolConfig>::Missing();
@@ -46,7 +45,7 @@ class DLL_EXPORT CASEClient
 
     void SetRemoteMRPIntervals(const ReliableMessageProtocolConfig & remoteMRPConfig);
 
-    CHIP_ERROR EstablishSession(PeerId peer, const Transport::PeerAddress & peerAddress,
+    CHIP_ERROR EstablishSession(const ScopedNodeId & peer, const Transport::PeerAddress & peerAddress,
                                 const ReliableMessageProtocolConfig & remoteMRPConfig, SessionEstablishmentDelegate * delegate);
 
 private:
diff --git a/src/app/CASESessionManager.cpp b/src/app/CASESessionManager.cpp
index 24fd9edc46617b..0f1d08fa46aeca 100644
--- a/src/app/CASESessionManager.cpp
+++ b/src/app/CASESessionManager.cpp
@@ -28,11 +28,11 @@ CHIP_ERROR CASESessionManager::Init(chip::System::Layer * systemLayer, const CAS
     return AddressResolve::Resolver::Instance().Init(systemLayer);
 }
 
-void CASESessionManager::FindOrEstablishSession(PeerId peerId, Callback::Callback<OnDeviceConnected> * onConnection,
+void CASESessionManager::FindOrEstablishSession(const ScopedNodeId & peerId, Callback::Callback<OnDeviceConnected> * onConnection,
                                                 Callback::Callback<OnDeviceConnectionFailure> * onFailure)
 {
-    ChipLogDetail(CASESessionManager, "FindOrEstablishSession: PeerId = " ChipLogFormatX64 ":" ChipLogFormatX64,
-                  ChipLogValueX64(peerId.GetCompressedFabricId()), ChipLogValueX64(peerId.GetNodeId()));
+    ChipLogDetail(CASESessionManager, "FindOrEstablishSession: PeerId = [%d:" ChipLogFormatX64 "]", peerId.GetFabricIndex(),
+                  ChipLogValueX64(peerId.GetNodeId()));
 
     OperationalDeviceProxy * session = FindExistingSession(peerId);
     if (session == nullptr)
@@ -64,7 +64,7 @@ void CASESessionManager::FindOrEstablishSession(PeerId peerId, Callback::Callbac
     }
 }
 
-void CASESessionManager::ReleaseSession(PeerId peerId)
+void CASESessionManager::ReleaseSession(const ScopedNodeId & peerId)
 {
     ReleaseSession(FindExistingSession(peerId));
 }
@@ -79,7 +79,7 @@ void CASESessionManager::ReleaseAllSessions()
     mConfig.devicePool->ReleaseAllDevices();
 }
 
-CHIP_ERROR CASESessionManager::GetPeerAddress(PeerId peerId, Transport::PeerAddress & addr)
+CHIP_ERROR CASESessionManager::GetPeerAddress(const ScopedNodeId & peerId, Transport::PeerAddress & addr)
 {
     OperationalDeviceProxy * session = FindExistingSession(peerId);
     VerifyOrReturnError(session != nullptr, CHIP_ERROR_NOT_CONNECTED);
@@ -87,7 +87,7 @@ CHIP_ERROR CASESessionManager::GetPeerAddress(PeerId peerId, Transport::PeerAddr
     return CHIP_NO_ERROR;
 }
 
-OperationalDeviceProxy * CASESessionManager::FindExistingSession(PeerId peerId) const
+OperationalDeviceProxy * CASESessionManager::FindExistingSession(const ScopedNodeId & peerId) const
 {
     return mConfig.devicePool->FindDevice(peerId);
 }
diff --git a/src/app/CASESessionManager.h b/src/app/CASESessionManager.h
index a464a40e37ce59..c74cb47748f874 100644
--- a/src/app/CASESessionManager.h
+++ b/src/app/CASESessionManager.h
@@ -68,12 +68,12 @@ class CASESessionManager
      * The `onFailure` callback may be called before the FindOrEstablishSession
      * call returns, for error cases that are detected synchronously.
      */
-    void FindOrEstablishSession(PeerId peerId, Callback::Callback<OnDeviceConnected> * onConnection,
+    void FindOrEstablishSession(const ScopedNodeId & peerId, Callback::Callback<OnDeviceConnected> * onConnection,
                                 Callback::Callback<OnDeviceConnectionFailure> * onFailure);
 
-    OperationalDeviceProxy * FindExistingSession(PeerId peerId) const;
+    OperationalDeviceProxy * FindExistingSession(const ScopedNodeId & peerId) const;
 
-    void ReleaseSession(PeerId peerId);
+    void ReleaseSession(const ScopedNodeId & peerId);
 
     void ReleaseSessionsForFabric(FabricIndex fabricIndex);
 
@@ -87,7 +87,7 @@ class CASESessionManager
      * an ongoing session with the peer node. If the session doesn't exist, the API will return
      * `CHIP_ERROR_NOT_CONNECTED` error.
      */
-    CHIP_ERROR GetPeerAddress(PeerId peerId, Transport::PeerAddress & addr);
+    CHIP_ERROR GetPeerAddress(const ScopedNodeId & peerId, Transport::PeerAddress & addr);
 
 private:
     void ReleaseSession(OperationalDeviceProxy * device) const;
diff --git a/src/app/OperationalDeviceProxy.cpp b/src/app/OperationalDeviceProxy.cpp
index 0e85731a6750d6..5852f727a65ae0 100644
--- a/src/app/OperationalDeviceProxy.cpp
+++ b/src/app/OperationalDeviceProxy.cpp
@@ -50,8 +50,8 @@ void OperationalDeviceProxy::MoveToState(State aTargetState)
 {
     if (mState != aTargetState)
     {
-        ChipLogDetail(Controller, "OperationalDeviceProxy[" ChipLogFormatX64 ":" ChipLogFormatX64 "]: State change %d --> %d",
-                      ChipLogValueX64(mPeerId.GetCompressedFabricId()), ChipLogValueX64(mPeerId.GetNodeId()), to_underlying(mState),
+        ChipLogDetail(Controller, "OperationalDeviceProxy[%u:" ChipLogFormatX64 "]: State change %d --> %d",
+                      mPeerId.GetFabricIndex(), ChipLogValueX64(mPeerId.GetNodeId()), to_underlying(mState),
                       to_underlying(aTargetState));
         mState = aTargetState;
 
@@ -66,14 +66,14 @@ bool OperationalDeviceProxy::AttachToExistingSecureSession()
 {
     VerifyOrReturnError(mState == State::NeedsAddress || mState == State::ResolvingAddress || mState == State::HasAddress, false);
 
-    ScopedNodeId peerNodeId(mPeerId.GetNodeId(), mFabricIndex);
     auto sessionHandle =
-        mInitParams.sessionManager->FindSecureSessionForNode(peerNodeId, MakeOptional(Transport::SecureSession::Type::kCASE));
+        mInitParams.sessionManager->FindSecureSessionForNode(mPeerId, MakeOptional(Transport::SecureSession::Type::kCASE));
     if (!sessionHandle.HasValue())
         return false;
 
-    ChipLogProgress(Controller, "Found an existing secure session to [" ChipLogFormatX64 "-" ChipLogFormatX64 "]!",
-                    ChipLogValueX64(mPeerId.GetCompressedFabricId()), ChipLogValueX64(mPeerId.GetNodeId()));
+    ChipLogProgress(Controller, "Found an existing secure session to [%u:" ChipLogFormatX64 "]!", mPeerId.GetFabricIndex(),
+                    ChipLogValueX64(mPeerId.GetNodeId()));
+
     mDeviceAddress = sessionHandle.Value()->AsSecureSession()->GetPeerAddress();
     if (!mSecureSession.Grab(sessionHandle.Value()))
         return false;
@@ -169,11 +169,8 @@ void OperationalDeviceProxy::UpdateDeviceData(const Transport::PeerAddress & add
     char peerAddrBuff[Transport::PeerAddress::kMaxToStringSize];
     addr.ToString(peerAddrBuff);
 
-    ChipLogDetail(Discovery,
-                  "OperationalDeviceProxy[" ChipLogFormatX64 ":" ChipLogFormatX64
-                  "]: Updating device address to %s while in state %d",
-                  ChipLogValueX64(mPeerId.GetCompressedFabricId()), ChipLogValueX64(mPeerId.GetNodeId()), peerAddrBuff,
-                  static_cast<int>(mState));
+    ChipLogDetail(Discovery, "OperationalDeviceProxy[%u:" ChipLogFormatX64 "]: Updating device address to %s while in state %d",
+                  mPeerId.GetFabricIndex(), ChipLogValueX64(mPeerId.GetNodeId()), peerAddrBuff, static_cast<int>(mState));
 #endif
 
     CHIP_ERROR err = CHIP_NO_ERROR;
@@ -216,7 +213,7 @@ CHIP_ERROR OperationalDeviceProxy::EstablishConnection()
 {
     mCASEClient = mInitParams.clientPool->Allocate(CASEClientInitParams{
         mInitParams.sessionManager, mInitParams.sessionResumptionStorage, mInitParams.certificateValidityPolicy,
-        mInitParams.exchangeMgr, mFabricTable, mFabricIndex, mInitParams.groupDataProvider, mInitParams.mrpLocalConfig });
+        mInitParams.exchangeMgr, mFabricTable, mInitParams.groupDataProvider, mInitParams.mrpLocalConfig });
     ReturnErrorCodeIf(mCASEClient == nullptr, CHIP_ERROR_NO_MEMORY);
 
     CHIP_ERROR err = mCASEClient->EstablishSession(mPeerId, mDeviceAddress, mRemoteMRPConfig, this);
@@ -363,7 +360,7 @@ void OperationalDeviceProxy::OnSessionHang()
 
 void OperationalDeviceProxy::ShutdownSubscriptions()
 {
-    app::InteractionModelEngine::GetInstance()->ShutdownSubscriptions(mFabricIndex, GetDeviceId());
+    app::InteractionModelEngine::GetInstance()->ShutdownSubscriptions(mPeerId.GetFabricIndex(), GetDeviceId());
 }
 
 OperationalDeviceProxy::~OperationalDeviceProxy()
@@ -371,9 +368,9 @@ OperationalDeviceProxy::~OperationalDeviceProxy()
     if (mAddressLookupHandle.IsActive())
     {
         ChipLogDetail(Discovery,
-                      "OperationalDeviceProxy[" ChipLogFormatX64 ":" ChipLogFormatX64
+                      "OperationalDeviceProxy[%u:" ChipLogFormatX64
                       "]: Cancelling incomplete address resolution as device is being deleted.",
-                      ChipLogValueX64(mPeerId.GetCompressedFabricId()), ChipLogValueX64(mPeerId.GetNodeId()));
+                      mPeerId.GetFabricIndex(), ChipLogValueX64(mPeerId.GetNodeId()));
 
         // Skip cancel callback since the destructor is being called, so we assume that this object is
         // obviously not used anymore
@@ -399,13 +396,18 @@ CHIP_ERROR OperationalDeviceProxy::LookupPeerAddress()
     if (mAddressLookupHandle.IsActive())
     {
         ChipLogProgress(Discovery,
-                        "OperationalDeviceProxy[" ChipLogFormatX64 ":" ChipLogFormatX64
+                        "OperationalDeviceProxy[%u:" ChipLogFormatX64
                         "]: Operational node lookup already in progress. Will NOT start a new one.",
-                        ChipLogValueX64(mPeerId.GetCompressedFabricId()), ChipLogValueX64(mPeerId.GetNodeId()));
+                        mPeerId.GetFabricIndex(), ChipLogValueX64(mPeerId.GetNodeId()));
         return CHIP_NO_ERROR;
     }
 
-    NodeLookupRequest request(mPeerId);
+    auto const * fabricInfo = mFabricTable->FindFabricWithIndex(mPeerId.GetFabricIndex());
+    VerifyOrReturnError(fabricInfo != nullptr, CHIP_ERROR_INVALID_FABRIC_INDEX);
+
+    PeerId peerId(fabricInfo->GetCompressedFabricId(), mPeerId.GetNodeId());
+
+    NodeLookupRequest request(peerId);
 
     return Resolver::Instance().LookupNode(request, mAddressLookupHandle);
 }
@@ -417,10 +419,8 @@ void OperationalDeviceProxy::OnNodeAddressResolved(const PeerId & peerId, const
 
 void OperationalDeviceProxy::OnNodeAddressResolutionFailed(const PeerId & peerId, CHIP_ERROR reason)
 {
-    ChipLogError(Discovery,
-                 "OperationalDeviceProxy[" ChipLogFormatX64 ":" ChipLogFormatX64
-                 "]: operational discovery failed: %" CHIP_ERROR_FORMAT,
-                 ChipLogValueX64(mPeerId.GetCompressedFabricId()), ChipLogValueX64(mPeerId.GetNodeId()), reason.Format());
+    ChipLogError(Discovery, "OperationalDeviceProxy[%u:" ChipLogFormatX64 "]: operational discovery failed: %" CHIP_ERROR_FORMAT,
+                 mPeerId.GetFabricIndex(), ChipLogValueX64(mPeerId.GetNodeId()), reason.Format());
 
     if (IsResolvingAddress())
     {
diff --git a/src/app/OperationalDeviceProxy.h b/src/app/OperationalDeviceProxy.h
index 3adf96b39af08a..f83bb7a2ab9613 100644
--- a/src/app/OperationalDeviceProxy.h
+++ b/src/app/OperationalDeviceProxy.h
@@ -73,7 +73,7 @@ struct DeviceProxyInitParams
 class OperationalDeviceProxy;
 
 typedef void (*OnDeviceConnected)(void * context, OperationalDeviceProxy * device);
-typedef void (*OnDeviceConnectionFailure)(void * context, PeerId peerId, CHIP_ERROR error);
+typedef void (*OnDeviceConnectionFailure)(void * context, const ScopedNodeId & peerId, CHIP_ERROR error);
 
 /**
  * Represents a connection path to a device that is in an operational state.
@@ -92,10 +92,7 @@ class DLL_EXPORT OperationalDeviceProxy : public DeviceProxy,
 public:
     ~OperationalDeviceProxy() override;
 
-    //
-    // TODO: Should not be PeerId, but rather, ScopedNodeId
-    //
-    OperationalDeviceProxy(DeviceProxyInitParams & params, PeerId peerId) : mSecureSession(*this)
+    OperationalDeviceProxy(DeviceProxyInitParams & params, ScopedNodeId peerId) : mSecureSession(*this)
     {
         mInitParams = params;
         if (params.Validate() != CHIP_NO_ERROR)
@@ -107,15 +104,7 @@ class DLL_EXPORT OperationalDeviceProxy : public DeviceProxy,
         mSystemLayer = params.exchangeMgr->GetSessionManager()->SystemLayer();
         mPeerId      = peerId;
         mFabricTable = params.fabricTable;
-        if (mFabricTable != nullptr)
-        {
-            auto fabricInfo = params.fabricTable->FindFabricWithCompressedId(peerId.GetCompressedFabricId());
-            if (fabricInfo != nullptr)
-            {
-                mFabricIndex = fabricInfo->GetFabricIndex();
-            }
-        }
-        mState = State::NeedsAddress;
+        mState       = State::NeedsAddress;
         mAddressLookupHandle.SetListener(this);
     }
 
@@ -171,7 +160,7 @@ class DLL_EXPORT OperationalDeviceProxy : public DeviceProxy,
 
     NodeId GetDeviceId() const override { return mPeerId.GetNodeId(); }
 
-    PeerId GetPeerId() const { return mPeerId; }
+    ScopedNodeId GetPeerId() const { return mPeerId; }
 
     void ShutdownSubscriptions() override;
 
@@ -201,7 +190,7 @@ class DLL_EXPORT OperationalDeviceProxy : public DeviceProxy,
     /**
      * @brief Get the fabricIndex
      */
-    FabricIndex GetFabricIndex() const { return mFabricIndex; }
+    FabricIndex GetFabricIndex() const { return mPeerId.GetFabricIndex(); }
 
     /**
      * Triggers a DNSSD lookup to find a usable peer address for this operational device.
@@ -225,14 +214,13 @@ class DLL_EXPORT OperationalDeviceProxy : public DeviceProxy,
 
     DeviceProxyInitParams mInitParams;
     FabricTable * mFabricTable = nullptr;
-    FabricIndex mFabricIndex   = kUndefinedFabricIndex;
     System::Layer * mSystemLayer;
 
     // mCASEClient is only non-null if we are in State::Connecting or just
     // allocated it as part of an attempt to enter State::Connecting.
     CASEClient * mCASEClient = nullptr;
 
-    PeerId mPeerId;
+    ScopedNodeId mPeerId;
 
     Transport::PeerAddress mDeviceAddress = Transport::PeerAddress::UDP(Inet::IPAddress::Any);
 
diff --git a/src/app/OperationalDeviceProxyPool.h b/src/app/OperationalDeviceProxyPool.h
index c6f3d7e136f152..5413624c4d9016 100644
--- a/src/app/OperationalDeviceProxyPool.h
+++ b/src/app/OperationalDeviceProxyPool.h
@@ -26,11 +26,11 @@ namespace chip {
 class OperationalDeviceProxyPoolDelegate
 {
 public:
-    virtual OperationalDeviceProxy * Allocate(DeviceProxyInitParams & params, PeerId peerId) = 0;
+    virtual OperationalDeviceProxy * Allocate(DeviceProxyInitParams & params, ScopedNodeId peerId) = 0;
 
     virtual void Release(OperationalDeviceProxy * device) = 0;
 
-    virtual OperationalDeviceProxy * FindDevice(PeerId peerId) = 0;
+    virtual OperationalDeviceProxy * FindDevice(ScopedNodeId peerId) = 0;
 
     virtual void ReleaseDevicesForFabric(FabricIndex fabricIndex) = 0;
 
@@ -45,14 +45,14 @@ class OperationalDeviceProxyPool : public OperationalDeviceProxyPoolDelegate
 public:
     ~OperationalDeviceProxyPool() override { mDevicePool.ReleaseAll(); }
 
-    OperationalDeviceProxy * Allocate(DeviceProxyInitParams & params, PeerId peerId) override
+    OperationalDeviceProxy * Allocate(DeviceProxyInitParams & params, ScopedNodeId peerId) override
     {
         return mDevicePool.CreateObject(params, peerId);
     }
 
     void Release(OperationalDeviceProxy * device) override { mDevicePool.ReleaseObject(device); }
 
-    OperationalDeviceProxy * FindDevice(PeerId peerId) override
+    OperationalDeviceProxy * FindDevice(ScopedNodeId peerId) override
     {
         OperationalDeviceProxy * foundDevice = nullptr;
         mDevicePool.ForEachActiveObject([&](auto * activeDevice) {
diff --git a/src/app/clusters/bindings/BindingManager.cpp b/src/app/clusters/bindings/BindingManager.cpp
index 5e8415b08f4668..73bcf93e0b9aff 100644
--- a/src/app/clusters/bindings/BindingManager.cpp
+++ b/src/app/clusters/bindings/BindingManager.cpp
@@ -50,16 +50,6 @@ BindingFabricTableDelegate gFabricTableDelegate;
 
 namespace {
 
-chip::PeerId PeerIdForNode(chip::FabricTable * fabricTable, chip::FabricIndex fabric, chip::NodeId node)
-{
-    const chip::FabricInfo * fabricInfo = fabricTable->FindFabricWithIndex(fabric);
-    if (fabricInfo == nullptr)
-    {
-        return chip::PeerId();
-    }
-    return fabricInfo->GetPeerIdForNode(node);
-}
-
 } // namespace
 
 namespace chip {
@@ -68,7 +58,7 @@ BindingManager BindingManager::sBindingManager;
 
 CHIP_ERROR BindingManager::UnicastBindingCreated(uint8_t fabricIndex, NodeId nodeId)
 {
-    return EstablishConnection(fabricIndex, nodeId);
+    return EstablishConnection(ScopedNodeId(nodeId, fabricIndex));
 }
 
 CHIP_ERROR BindingManager::UnicastBindingRemoved(uint8_t bindingEntryId)
@@ -106,29 +96,26 @@ CHIP_ERROR BindingManager::Init(const BindingManagerInitParams & params)
     return CHIP_NO_ERROR;
 }
 
-CHIP_ERROR BindingManager::EstablishConnection(FabricIndex fabric, NodeId node)
+CHIP_ERROR BindingManager::EstablishConnection(const ScopedNodeId & nodeId)
 {
     VerifyOrReturnError(mInitParams.mCASESessionManager != nullptr, CHIP_ERROR_INCORRECT_STATE);
-    PeerId peer = PeerIdForNode(mInitParams.mFabricTable, fabric, node);
-    VerifyOrReturnError(peer.GetNodeId() != kUndefinedNodeId, CHIP_ERROR_NOT_FOUND);
 
     mLastSessionEstablishmentError = CHIP_NO_ERROR;
-    mInitParams.mCASESessionManager->FindOrEstablishSession(peer, &mOnConnectedCallback, &mOnConnectionFailureCallback);
+    mInitParams.mCASESessionManager->FindOrEstablishSession(nodeId, &mOnConnectedCallback, &mOnConnectionFailureCallback);
     if (mLastSessionEstablishmentError == CHIP_ERROR_NO_MEMORY)
     {
         // Release the least recently used entry
         // TODO: Some reference counting mechanism shall be added the CASESessionManager
         // so that other session clients don't get accidentally closed.
-        FabricIndex fabricToRemove;
-        NodeId nodeToRemove;
-        if (mPendingNotificationMap.FindLRUConnectPeer(&fabricToRemove, &nodeToRemove) == CHIP_NO_ERROR)
+        ScopedNodeId peerToRemove;
+        if (mPendingNotificationMap.FindLRUConnectPeer(peerToRemove) == CHIP_NO_ERROR)
         {
-            mPendingNotificationMap.RemoveAllEntriesForNode(fabricToRemove, nodeToRemove);
-            PeerId lruPeer = PeerIdForNode(mInitParams.mFabricTable, fabricToRemove, nodeToRemove);
-            mInitParams.mCASESessionManager->ReleaseSession(lruPeer);
+            mPendingNotificationMap.RemoveAllEntriesForNode(peerToRemove);
+            mInitParams.mCASESessionManager->ReleaseSession(peerToRemove);
+
             // Now retry
             mLastSessionEstablishmentError = CHIP_NO_ERROR;
-            mInitParams.mCASESessionManager->FindOrEstablishSession(peer, &mOnConnectedCallback, &mOnConnectionFailureCallback);
+            mInitParams.mCASESessionManager->FindOrEstablishSession(nodeId, &mOnConnectedCallback, &mOnConnectionFailureCallback);
         }
     }
     return mLastSessionEstablishmentError;
@@ -151,24 +138,24 @@ void BindingManager::HandleDeviceConnected(OperationalDeviceProxy * device)
     {
         EmberBindingTableEntry entry = BindingTable::GetInstance().GetAt(pendingNotification.mBindingEntryId);
 
-        PeerId peer = PeerIdForNode(mInitParams.mFabricTable, entry.fabricIndex, entry.nodeId);
-        if (device->GetPeerId() == peer)
+        if (device->GetPeerId() == ScopedNodeId(entry.nodeId, entry.fabricIndex))
         {
             fabricToRemove = entry.fabricIndex;
             nodeToRemove   = entry.nodeId;
             mBoundDeviceChangedHandler(entry, device, pendingNotification.mContext->GetContext());
         }
     }
-    mPendingNotificationMap.RemoveAllEntriesForNode(fabricToRemove, nodeToRemove);
+
+    mPendingNotificationMap.RemoveAllEntriesForNode(ScopedNodeId(nodeToRemove, fabricToRemove));
 }
 
-void BindingManager::HandleDeviceConnectionFailure(void * context, PeerId peerId, CHIP_ERROR error)
+void BindingManager::HandleDeviceConnectionFailure(void * context, const ScopedNodeId & peerId, CHIP_ERROR error)
 {
     BindingManager * manager = static_cast<BindingManager *>(context);
     manager->HandleDeviceConnectionFailure(peerId, error);
 }
 
-void BindingManager::HandleDeviceConnectionFailure(PeerId peerId, CHIP_ERROR error)
+void BindingManager::HandleDeviceConnectionFailure(const ScopedNodeId & peerId, CHIP_ERROR error)
 {
     // Simply release the entry, the connection will be re-established as needed.
     ChipLogError(AppServer, "Failed to establish connection to node 0x" ChipLogFormatX64, ChipLogValueX64(peerId.GetNodeId()));
@@ -202,10 +189,8 @@ CHIP_ERROR BindingManager::NotifyBoundClusterChanged(EndpointId endpoint, Cluste
         {
             if (iter->type == EMBER_UNICAST_BINDING)
             {
-                const FabricInfo * fabricInfo = mInitParams.mFabricTable->FindFabricWithIndex(iter->fabricIndex);
-                VerifyOrReturnError(fabricInfo != nullptr, CHIP_ERROR_NOT_FOUND);
-                PeerId peer                         = fabricInfo->GetPeerIdForNode(iter->nodeId);
-                OperationalDeviceProxy * peerDevice = mInitParams.mCASESessionManager->FindExistingSession(peer);
+                OperationalDeviceProxy * peerDevice =
+                    mInitParams.mCASESessionManager->FindExistingSession(ScopedNodeId(iter->nodeId, iter->fabricIndex));
                 if (peerDevice != nullptr && peerDevice->IsConnected())
                 {
                     // We already have an active connection
@@ -214,7 +199,7 @@ CHIP_ERROR BindingManager::NotifyBoundClusterChanged(EndpointId endpoint, Cluste
                 else
                 {
                     mPendingNotificationMap.AddPendingNotification(iter.GetIndex(), bindingContext);
-                    error = EstablishConnection(iter->fabricIndex, iter->nodeId);
+                    error = EstablishConnection(ScopedNodeId(iter->nodeId, iter->fabricIndex));
                     SuccessOrExit(error == CHIP_NO_ERROR);
                 }
             }
diff --git a/src/app/clusters/bindings/BindingManager.h b/src/app/clusters/bindings/BindingManager.h
index 86b01795d140dd..308b672a482590 100644
--- a/src/app/clusters/bindings/BindingManager.h
+++ b/src/app/clusters/bindings/BindingManager.h
@@ -126,10 +126,10 @@ class BindingManager
     static void HandleDeviceConnected(void * context, OperationalDeviceProxy * device);
     void HandleDeviceConnected(OperationalDeviceProxy * device);
 
-    static void HandleDeviceConnectionFailure(void * context, PeerId peerId, CHIP_ERROR error);
-    void HandleDeviceConnectionFailure(PeerId peerId, CHIP_ERROR error);
+    static void HandleDeviceConnectionFailure(void * context, const ScopedNodeId & peerId, CHIP_ERROR error);
+    void HandleDeviceConnectionFailure(const ScopedNodeId & peerId, CHIP_ERROR error);
 
-    CHIP_ERROR EstablishConnection(FabricIndex fabric, NodeId node);
+    CHIP_ERROR EstablishConnection(const ScopedNodeId & nodeId);
 
     PendingNotificationMap mPendingNotificationMap;
     BoundDeviceChangedHandler mBoundDeviceChangedHandler;
diff --git a/src/app/clusters/bindings/PendingNotificationMap.cpp b/src/app/clusters/bindings/PendingNotificationMap.cpp
index 6676a82b779d4d..a7e6adb595ce59 100644
--- a/src/app/clusters/bindings/PendingNotificationMap.cpp
+++ b/src/app/clusters/bindings/PendingNotificationMap.cpp
@@ -22,7 +22,7 @@
 
 namespace chip {
 
-CHIP_ERROR PendingNotificationMap::FindLRUConnectPeer(FabricIndex * fabric, NodeId * node)
+CHIP_ERROR PendingNotificationMap::FindLRUConnectPeer(ScopedNodeId & nodeId)
 {
     // When entries are added to PendingNotificationMap, they are appended to the end.
     // To find the LRU peer, we need to find the peer whose last entry in the map is closer
@@ -72,8 +72,7 @@ CHIP_ERROR PendingNotificationMap::FindLRUConnectPeer(FabricIndex * fabric, Node
     if (minLastAppearValue < UINT16_MAX)
     {
         EmberBindingTableEntry entry = BindingTable::GetInstance().GetAt(static_cast<uint8_t>(lruBindingEntryIndex));
-        *fabric                      = entry.fabricIndex;
-        *node                        = entry.nodeId;
+        nodeId                       = ScopedNodeId(entry.nodeId, entry.fabricIndex);
         return CHIP_NO_ERROR;
     }
     return CHIP_ERROR_NOT_FOUND;
@@ -110,13 +109,13 @@ void PendingNotificationMap::RemoveEntry(uint8_t bindingEntryId)
     mNumEntries = newEntryCount;
 }
 
-void PendingNotificationMap::RemoveAllEntriesForNode(FabricIndex fabric, NodeId node)
+void PendingNotificationMap::RemoveAllEntriesForNode(const ScopedNodeId & nodeId)
 {
     uint8_t newEntryCount = 0;
     for (int i = 0; i < mNumEntries; i++)
     {
         EmberBindingTableEntry entry = BindingTable::GetInstance().GetAt(mPendingBindingEntries[i]);
-        if (entry.fabricIndex != fabric || entry.nodeId != node)
+        if (entry.fabricIndex != nodeId.GetFabricIndex() || entry.nodeId != nodeId.GetNodeId())
         {
             mPendingBindingEntries[newEntryCount] = mPendingBindingEntries[i];
             mPendingContexts[newEntryCount]       = mPendingContexts[i];
diff --git a/src/app/clusters/bindings/PendingNotificationMap.h b/src/app/clusters/bindings/PendingNotificationMap.h
index 5ef12ee560cbad..2e70a0718d047b 100644
--- a/src/app/clusters/bindings/PendingNotificationMap.h
+++ b/src/app/clusters/bindings/PendingNotificationMap.h
@@ -100,15 +100,13 @@ class PendingNotificationMap
 
     Iterator end() { return Iterator(this, mNumEntries); }
 
-    CHIP_ERROR FindLRUConnectPeer(FabricIndex * fabric, NodeId * node);
+    CHIP_ERROR FindLRUConnectPeer(ScopedNodeId & nodeId);
 
     void AddPendingNotification(uint8_t bindingEntryId, PendingNotificationContext * context);
 
     void RemoveEntry(uint8_t bindingEntryId);
 
-    void RemoveAllEntriesForNode(FabricTable * fabricTable, PeerId peer);
-
-    void RemoveAllEntriesForNode(FabricIndex fabric, NodeId node);
+    void RemoveAllEntriesForNode(const ScopedNodeId & nodeId);
 
     void RemoveAllEntriesForFabric(FabricIndex fabric);
 
diff --git a/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp b/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp
index 603d3874ec4369..1aecdb3022ae27 100644
--- a/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp
+++ b/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp
@@ -366,23 +366,13 @@ void DefaultOTARequestor::ConnectToProvider(OnConnectedAction onConnectedAction)
         return;
     }
 
-    const FabricInfo * fabricInfo = mServer->GetFabricTable().FindFabricWithIndex(mProviderLocation.Value().fabricIndex);
-
-    if (fabricInfo == nullptr)
-    {
-        ChipLogError(SoftwareUpdate, "Cannot find fabric");
-        RecordErrorUpdateState(CHIP_ERROR_INCORRECT_STATE);
-        return;
-    }
-
     // Set the action to take once connection is successfully established
     mOnConnectedAction = onConnectedAction;
 
     ChipLogDetail(SoftwareUpdate, "Establishing session to provider node ID 0x" ChipLogFormatX64 " on fabric index %d",
                   ChipLogValueX64(mProviderLocation.Value().providerNodeID), mProviderLocation.Value().fabricIndex);
 
-    mCASESessionManager->FindOrEstablishSession(fabricInfo->GetPeerIdForNode(mProviderLocation.Value().providerNodeID),
-                                                &mOnConnectedCallback, &mOnConnectionFailureCallback);
+    mCASESessionManager->FindOrEstablishSession(GetProviderScopedId(), &mOnConnectedCallback, &mOnConnectionFailureCallback);
 }
 
 void DefaultOTARequestor::DisconnectFromProvider()
@@ -396,17 +386,9 @@ void DefaultOTARequestor::DisconnectFromProvider()
         return;
     }
 
-    const FabricInfo * fabricInfo = mServer->GetFabricTable().FindFabricWithIndex(mProviderLocation.Value().fabricIndex);
-    if (fabricInfo == nullptr)
-    {
-        ChipLogError(SoftwareUpdate, "Cannot find fabric");
-        RecordErrorUpdateState(CHIP_ERROR_INCORRECT_STATE);
-        return;
-    }
-
-    PeerId peerID = fabricInfo->GetPeerIdForNode(mProviderLocation.Value().providerNodeID);
-    mCASESessionManager->FindExistingSession(peerID)->Disconnect();
-    mCASESessionManager->ReleaseSession(peerID);
+    auto providerNodeId = GetProviderScopedId();
+    mCASESessionManager->FindExistingSession(providerNodeId)->Disconnect();
+    mCASESessionManager->ReleaseSession(providerNodeId);
 }
 
 // Requestor is directed to cancel image update in progress. All the Requestor state is
@@ -492,7 +474,7 @@ void DefaultOTARequestor::OnConnected(void * context, OperationalDeviceProxy * d
 }
 
 // Called whenever FindOrEstablishSession fails
-void DefaultOTARequestor::OnConnectionFailure(void * context, PeerId peerId, CHIP_ERROR error)
+void DefaultOTARequestor::OnConnectionFailure(void * context, const ScopedNodeId & peerId, CHIP_ERROR error)
 {
     DefaultOTARequestor * requestorCore = static_cast<DefaultOTARequestor *>(context);
     VerifyOrDie(requestorCore != nullptr);
diff --git a/src/app/clusters/ota-requestor/DefaultOTARequestor.h b/src/app/clusters/ota-requestor/DefaultOTARequestor.h
index 49b8dfeb865859..f80f7555fe05ee 100644
--- a/src/app/clusters/ota-requestor/DefaultOTARequestor.h
+++ b/src/app/clusters/ota-requestor/DefaultOTARequestor.h
@@ -205,6 +205,12 @@ class DefaultOTARequestor : public OTARequestorInterface, public BDXDownloader::
      */
     IdleStateReason MapErrorToIdleStateReason(CHIP_ERROR error);
 
+    ScopedNodeId GetProviderScopedId() const
+    {
+        VerifyOrDie(mProviderLocation.HasValue());
+        return ScopedNodeId(mProviderLocation.Value().providerNodeID, mProviderLocation.Value().fabricIndex);
+    }
+
     /**
      * Record the new update state by updating the corresponding server attribute and logging a StateTransition event
      */
@@ -280,7 +286,7 @@ class DefaultOTARequestor : public OTARequestorInterface, public BDXDownloader::
      * Session connection callbacks
      */
     static void OnConnected(void * context, OperationalDeviceProxy * deviceProxy);
-    static void OnConnectionFailure(void * context, PeerId peerId, CHIP_ERROR error);
+    static void OnConnectionFailure(void * context, const ScopedNodeId & peerId, CHIP_ERROR error);
     Callback::Callback<OnDeviceConnected> mOnConnectedCallback;
     Callback::Callback<OnDeviceConnectionFailure> mOnConnectionFailureCallback;
 
diff --git a/src/app/tests/TestPendingNotificationMap.cpp b/src/app/tests/TestPendingNotificationMap.cpp
index 621f8ad1c84f0a..271b427f31013a 100644
--- a/src/app/tests/TestPendingNotificationMap.cpp
+++ b/src/app/tests/TestPendingNotificationMap.cpp
@@ -53,9 +53,8 @@ void TestEmptyMap(nlTestSuite * aSuite, void * aContext)
 {
     PendingNotificationMap pendingMap;
     NL_TEST_ASSERT(aSuite, pendingMap.begin() == pendingMap.end());
-    FabricIndex fabricIndex;
-    NodeId node;
-    NL_TEST_ASSERT(aSuite, pendingMap.FindLRUConnectPeer(&fabricIndex, &node) == CHIP_ERROR_NOT_FOUND);
+    chip::ScopedNodeId peer;
+    NL_TEST_ASSERT(aSuite, pendingMap.FindLRUConnectPeer(peer) == CHIP_ERROR_NOT_FOUND);
 }
 
 void TestAddRemove(nlTestSuite * aSuite, void * aContext)
@@ -75,7 +74,7 @@ void TestAddRemove(nlTestSuite * aSuite, void * aContext)
         ++iter;
     }
     NL_TEST_ASSERT(aSuite, iter == pendingMap.end());
-    pendingMap.RemoveAllEntriesForNode(0, 0);
+    pendingMap.RemoveAllEntriesForNode(chip::ScopedNodeId());
     uint8_t expectedEntryIndecies[] = { 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 };
     iter                            = pendingMap.begin();
     for (size_t i = 0; i < sizeof(expectedEntryIndecies); i++)
@@ -109,19 +108,18 @@ void TestLRUEntry(nlTestSuite * aSuite, void * aContext)
     pendingMap.AddPendingNotification(7, nullptr);
     pendingMap.AddPendingNotification(11, nullptr);
 
-    FabricIndex fabricIndex;
-    NodeId node;
+    chip::ScopedNodeId node;
 
-    NL_TEST_ASSERT(aSuite, pendingMap.FindLRUConnectPeer(&fabricIndex, &node) == CHIP_NO_ERROR);
-    NL_TEST_ASSERT(aSuite, fabricIndex == 0 && node == 1);
+    NL_TEST_ASSERT(aSuite, pendingMap.FindLRUConnectPeer(node) == CHIP_NO_ERROR);
+    NL_TEST_ASSERT(aSuite, node.GetFabricIndex() == 0 && node.GetNodeId() == 1);
 
     pendingMap.RemoveEntry(1);
-    NL_TEST_ASSERT(aSuite, pendingMap.FindLRUConnectPeer(&fabricIndex, &node) == CHIP_NO_ERROR);
-    NL_TEST_ASSERT(aSuite, fabricIndex == 0 && node == 0);
+    NL_TEST_ASSERT(aSuite, pendingMap.FindLRUConnectPeer(node) == CHIP_NO_ERROR);
+    NL_TEST_ASSERT(aSuite, node.GetFabricIndex() == 0 && node.GetNodeId() == 0);
 
     pendingMap.RemoveAllEntriesForFabric(0);
-    NL_TEST_ASSERT(aSuite, pendingMap.FindLRUConnectPeer(&fabricIndex, &node) == CHIP_NO_ERROR);
-    NL_TEST_ASSERT(aSuite, fabricIndex == 1 && node == 1);
+    NL_TEST_ASSERT(aSuite, pendingMap.FindLRUConnectPeer(node) == CHIP_NO_ERROR);
+    NL_TEST_ASSERT(aSuite, node.GetFabricIndex() == 1 && node.GetNodeId() == 1);
 }
 
 } // namespace
diff --git a/src/controller/CHIPDeviceController.cpp b/src/controller/CHIPDeviceController.cpp
index 9254f21d40b5e3..76249390570ac0 100644
--- a/src/controller/CHIPDeviceController.cpp
+++ b/src/controller/CHIPDeviceController.cpp
@@ -321,14 +321,14 @@ void DeviceController::ReleaseOperationalDevice(NodeId remoteNodeId)
 {
     VerifyOrReturn(mState == State::Initialized && mFabricIndex != kUndefinedFabricIndex,
                    ChipLogError(Controller, "ReleaseOperationalDevice was called in incorrect state"));
-    mSystemState->CASESessionMgr()->ReleaseSession(PeerId(GetCompressedFabricId(), remoteNodeId));
+    mSystemState->CASESessionMgr()->ReleaseSession(GetPeerScopedId(remoteNodeId));
 }
 
 CHIP_ERROR DeviceController::DisconnectDevice(NodeId nodeId)
 {
     ChipLogProgress(Controller, "Force close session for node 0x%" PRIx64, nodeId);
 
-    OperationalDeviceProxy * proxy = mSystemState->CASESessionMgr()->FindExistingSession(PeerId(GetCompressedFabricId(), nodeId));
+    OperationalDeviceProxy * proxy = mSystemState->CASESessionMgr()->FindExistingSession(GetPeerScopedId(nodeId));
     if (proxy == nullptr)
     {
         ChipLogProgress(Controller, "Attempted to close a session that does not exist.");
@@ -353,11 +353,11 @@ CHIP_ERROR DeviceController::DisconnectDevice(NodeId nodeId)
     return CHIP_NO_ERROR;
 }
 
-CHIP_ERROR DeviceController::GetPeerAddressAndPort(PeerId peerId, Inet::IPAddress & addr, uint16_t & port)
+CHIP_ERROR DeviceController::GetPeerAddressAndPort(NodeId peerId, Inet::IPAddress & addr, uint16_t & port)
 {
     VerifyOrReturnError(mState == State::Initialized, CHIP_ERROR_INCORRECT_STATE);
     Transport::PeerAddress peerAddr;
-    ReturnErrorOnFailure(mSystemState->CASESessionMgr()->GetPeerAddress(peerId, peerAddr));
+    ReturnErrorOnFailure(mSystemState->CASESessionMgr()->GetPeerAddress(GetPeerScopedId(peerId), peerAddr));
     addr = peerAddr.GetIPAddress();
     port = peerAddr.GetPort();
     return CHIP_NO_ERROR;
@@ -366,8 +366,8 @@ CHIP_ERROR DeviceController::GetPeerAddressAndPort(PeerId peerId, Inet::IPAddres
 CHIP_ERROR DeviceController::GetPeerAddress(NodeId nodeId, Transport::PeerAddress & addr)
 {
     VerifyOrReturnError(mState == State::Initialized, CHIP_ERROR_INCORRECT_STATE);
-    ReturnErrorOnFailure(mSystemState->CASESessionMgr()->GetPeerAddress(
-        PeerId().SetCompressedFabricId(GetCompressedFabricId()).SetNodeId(nodeId), addr));
+    ReturnErrorOnFailure(mSystemState->CASESessionMgr()->GetPeerAddress(GetPeerScopedId(nodeId), addr));
+
     return CHIP_NO_ERROR;
 }
 
@@ -1601,7 +1601,7 @@ void DeviceCommissioner::OnDeviceConnectedFn(void * context, OperationalDevicePr
     }
 }
 
-void DeviceCommissioner::OnDeviceConnectionFailureFn(void * context, PeerId peerId, CHIP_ERROR error)
+void DeviceCommissioner::OnDeviceConnectionFailureFn(void * context, const ScopedNodeId & peerId, CHIP_ERROR error)
 {
     // CASE session establishment failed.
     DeviceCommissioner * commissioner = static_cast<DeviceCommissioner *>(context);
@@ -2103,6 +2103,7 @@ void DeviceCommissioner::PerformCommissioningStep(DeviceProxy * proxy, Commissio
             CommissioningStageComplete(err);
             return;
         }
+
         err = proxy->SetPeerId(params.GetRootCert().Value(), params.GetNoc().Value());
         if (err != CHIP_NO_ERROR)
         {
@@ -2217,18 +2218,18 @@ CHIP_ERROR DeviceController::UpdateDevice(NodeId peerNodeId)
 {
     VerifyOrReturnError(mState == State::Initialized && mFabricIndex != kUndefinedFabricIndex, CHIP_ERROR_INCORRECT_STATE);
 
-    OperationalDeviceProxy * proxy = GetDeviceSession(PeerId(GetCompressedFabricId(), peerNodeId));
+    OperationalDeviceProxy * proxy = GetDeviceSession(GetPeerScopedId(peerNodeId));
     VerifyOrReturnError(proxy != nullptr, CHIP_ERROR_NOT_FOUND);
 
     return proxy->LookupPeerAddress();
 }
 
-OperationalDeviceProxy * DeviceController::GetDeviceSession(const PeerId & peerId)
+OperationalDeviceProxy * DeviceController::GetDeviceSession(const ScopedNodeId & peerId)
 {
     return mSystemState->CASESessionMgr()->FindExistingSession(peerId);
 }
 
-OperationalDeviceProxy * DeviceCommissioner::GetDeviceSession(const PeerId & peerId)
+OperationalDeviceProxy * DeviceCommissioner::GetDeviceSession(const ScopedNodeId & peerId)
 {
     mSystemState->CASESessionMgr()->FindOrEstablishSession(peerId, &mOnDeviceConnectedCallback,
                                                            &mOnDeviceConnectionFailureCallback);
diff --git a/src/controller/CHIPDeviceController.h b/src/controller/CHIPDeviceController.h
index 67ecfe2146e4b5..c647ea4dc4a10b 100644
--- a/src/controller/CHIPDeviceController.h
+++ b/src/controller/CHIPDeviceController.h
@@ -165,19 +165,21 @@ class DLL_EXPORT DeviceController : public AbstractDnssdDiscoveryController
         return nullptr;
     }
 
-    CHIP_ERROR GetPeerAddressAndPort(PeerId peerId, Inet::IPAddress & addr, uint16_t & port);
+    CHIP_ERROR GetPeerAddressAndPort(NodeId peerId, Inet::IPAddress & addr, uint16_t & port);
 
     /**
      * @brief
      *   Looks up the PeerAddress for an established CASE session.
      *
-     * @param[in] nodeId the PeerId of the session to be found
+     * @param[in] nodeId the NodeId of the target.
      * @param[out] addr the PeerAddress to be filled on success
      *
      * @return CHIP_ERROR CHIP_ERROR_NOT_CONNECTED if no CASE session exists for the device
      */
     CHIP_ERROR GetPeerAddress(NodeId nodeId, Transport::PeerAddress & addr);
 
+    ScopedNodeId GetPeerScopedId(NodeId nodeId) { return ScopedNodeId(nodeId, GetFabricIndex()); }
+
     /**
      * This function finds the device corresponding to deviceId, and establishes
      * a CASE session with it.
@@ -196,8 +198,7 @@ class DLL_EXPORT DeviceController : public AbstractDnssdDiscoveryController
                                   chip::Callback::Callback<OnDeviceConnectionFailure> * onFailure)
     {
         VerifyOrReturnError(mState == State::Initialized, CHIP_ERROR_INCORRECT_STATE);
-        mSystemState->CASESessionMgr()->FindOrEstablishSession(PeerId(GetCompressedFabricId(), peerNodeId), onConnection,
-                                                               onFailure);
+        mSystemState->CASESessionMgr()->FindOrEstablishSession(ScopedNodeId(peerNodeId, GetFabricIndex()), onConnection, onFailure);
         return CHIP_NO_ERROR;
     }
 
@@ -358,7 +359,7 @@ class DLL_EXPORT DeviceController : public AbstractDnssdDiscoveryController
 
     /// Fetches the session to use for the current device. Allows overriding
     /// in case subclasses want to create the session if it does not yet exist
-    virtual OperationalDeviceProxy * GetDeviceSession(const PeerId & peerId);
+    virtual OperationalDeviceProxy * GetDeviceSession(const ScopedNodeId & peerId);
 
     DiscoveredNodeList GetDiscoveredNodes() override { return DiscoveredNodeList(mCommissionableNodes); }
 
@@ -648,7 +649,7 @@ class DLL_EXPORT DeviceCommissioner : public DeviceController,
     void OnDone(app::ReadClient *) override;
 
     // Commissioner will establish new device connections after PASE.
-    OperationalDeviceProxy * GetDeviceSession(const PeerId & peerId) override;
+    OperationalDeviceProxy * GetDeviceSession(const ScopedNodeId & peerId) override;
 
     // Issue an NOC chain using the associated OperationalCredentialsDelegate. The NOC chain will
     // be provided in X509 DER format.
@@ -748,7 +749,7 @@ class DLL_EXPORT DeviceCommissioner : public DeviceController,
     static void OnRootCertFailureResponse(void * context, CHIP_ERROR error);
 
     static void OnDeviceConnectedFn(void * context, OperationalDeviceProxy * device);
-    static void OnDeviceConnectionFailureFn(void * context, PeerId peerId, CHIP_ERROR error);
+    static void OnDeviceConnectionFailureFn(void * context, const ScopedNodeId & peerId, CHIP_ERROR error);
 
     static void OnDeviceAttestationInformationVerification(void * context, Credentials::AttestationVerificationResult result);
 
diff --git a/src/controller/CommissioningWindowOpener.cpp b/src/controller/CommissioningWindowOpener.cpp
index c0761cac49e111..d0c9a186a5fc99 100644
--- a/src/controller/CommissioningWindowOpener.cpp
+++ b/src/controller/CommissioningWindowOpener.cpp
@@ -308,7 +308,7 @@ void CommissioningWindowOpener::OnDeviceConnectedCallback(void * context, Operat
     }
 }
 
-void CommissioningWindowOpener::OnDeviceConnectionFailureCallback(void * context, PeerId peerId, CHIP_ERROR error)
+void CommissioningWindowOpener::OnDeviceConnectionFailureCallback(void * context, const ScopedNodeId & peerId, CHIP_ERROR error)
 {
     OnOpenCommissioningWindowFailure(context, error);
 }
diff --git a/src/controller/CommissioningWindowOpener.h b/src/controller/CommissioningWindowOpener.h
index 30be3d90051557..63a073122e8d3e 100644
--- a/src/controller/CommissioningWindowOpener.h
+++ b/src/controller/CommissioningWindowOpener.h
@@ -127,7 +127,7 @@ class CommissioningWindowOpener
     static void OnOpenCommissioningWindowSuccess(void * context, const app::DataModel::NullObjectType &);
     static void OnOpenCommissioningWindowFailure(void * context, CHIP_ERROR error);
     static void OnDeviceConnectedCallback(void * context, OperationalDeviceProxy * device);
-    static void OnDeviceConnectionFailureCallback(void * context, PeerId peerId, CHIP_ERROR error);
+    static void OnDeviceConnectionFailureCallback(void * context, const ScopedNodeId & peerId, CHIP_ERROR error);
 
     DeviceController * const mController = nullptr;
     Step mNextStep                       = Step::kAcceptCommissioningStart;
diff --git a/src/controller/java/AndroidCallbacks.cpp b/src/controller/java/AndroidCallbacks.cpp
index 588f47c14a9389..56cf454c4429cb 100644
--- a/src/controller/java/AndroidCallbacks.cpp
+++ b/src/controller/java/AndroidCallbacks.cpp
@@ -82,7 +82,7 @@ void GetConnectedDeviceCallback::OnDeviceConnectedFn(void * context, Operational
     env->CallVoidMethod(javaCallback, successMethod, reinterpret_cast<jlong>(device));
 }
 
-void GetConnectedDeviceCallback::OnDeviceConnectionFailureFn(void * context, PeerId peerId, CHIP_ERROR error)
+void GetConnectedDeviceCallback::OnDeviceConnectionFailureFn(void * context, const ScopedNodeId & peerId, CHIP_ERROR error)
 {
     JNIEnv * env         = JniReferences::GetInstance().GetEnvForCurrentThread();
     auto * self          = static_cast<GetConnectedDeviceCallback *>(context);
diff --git a/src/controller/java/AndroidCallbacks.h b/src/controller/java/AndroidCallbacks.h
index 51c38d3c2b4e1a..7d1dbb4434b964 100644
--- a/src/controller/java/AndroidCallbacks.h
+++ b/src/controller/java/AndroidCallbacks.h
@@ -34,7 +34,7 @@ struct GetConnectedDeviceCallback
     ~GetConnectedDeviceCallback();
 
     static void OnDeviceConnectedFn(void * context, OperationalDeviceProxy * device);
-    static void OnDeviceConnectionFailureFn(void * context, PeerId peerId, CHIP_ERROR error);
+    static void OnDeviceConnectionFailureFn(void * context, const ScopedNodeId & peerId, CHIP_ERROR error);
 
     Callback::Callback<OnDeviceConnected> mOnSuccess;
     Callback::Callback<OnDeviceConnectionFailure> mOnFailure;
diff --git a/src/controller/java/CHIPDeviceController-JNI.cpp b/src/controller/java/CHIPDeviceController-JNI.cpp
index 7277ab1f91f580..59f6f417f1d762 100644
--- a/src/controller/java/CHIPDeviceController-JNI.cpp
+++ b/src/controller/java/CHIPDeviceController-JNI.cpp
@@ -523,11 +523,7 @@ JNI_METHOD(jstring, getIpAddress)(JNIEnv * env, jobject self, jlong handle, jlon
     uint16_t port;
     char addrStr[50];
 
-    CHIP_ERROR err =
-        wrapper->Controller()->GetPeerAddressAndPort(PeerId()
-                                                         .SetCompressedFabricId(wrapper->Controller()->GetCompressedFabricId())
-                                                         .SetNodeId(static_cast<chip::NodeId>(deviceId)),
-                                                     addr, port);
+    CHIP_ERROR err = wrapper->Controller()->GetPeerAddressAndPort(deviceId, addr, port);
 
     if (err != CHIP_NO_ERROR)
     {
diff --git a/src/controller/python/ChipDeviceController-ScriptBinding.cpp b/src/controller/python/ChipDeviceController-ScriptBinding.cpp
index 6927c6c65f4b1e..355a233561e9b6 100644
--- a/src/controller/python/ChipDeviceController-ScriptBinding.cpp
+++ b/src/controller/python/ChipDeviceController-ScriptBinding.cpp
@@ -298,12 +298,9 @@ ChipError::StorageType pychip_DeviceController_GetAddressAndPort(chip::Controlle
                                                                  uint16_t * outPort)
 {
     Inet::IPAddress address;
-    ReturnErrorOnFailure(
-        devCtrl
-            ->GetPeerAddressAndPort(PeerId().SetCompressedFabricId(devCtrl->GetCompressedFabricId()).SetNodeId(nodeId), address,
-                                    *outPort)
-            .AsInteger());
-    VerifyOrReturnError(address.ToString(outAddress, maxAddressLen), CHIP_ERROR_BUFFER_TOO_SMALL.AsInteger());
+    ReturnErrorOnFailure(devCtrl->GetPeerAddressAndPort(nodeId, address, *outPort).AsInteger());
+    VerifyOrReturnError(address.ToString(outAddress, static_cast<uint32_t>(maxAddressLen)),
+                        CHIP_ERROR_BUFFER_TOO_SMALL.AsInteger());
 
     return CHIP_NO_ERROR.AsInteger();
 }
@@ -621,7 +618,7 @@ struct GetDeviceCallbacks
         delete self;
     }
 
-    static void OnConnectionFailureFn(void * context, PeerId peerId, CHIP_ERROR error)
+    static void OnConnectionFailureFn(void * context, const ScopedNodeId & peerId, CHIP_ERROR error)
     {
         auto * self = static_cast<GetDeviceCallbacks *>(context);
         self->mCallback(nullptr, error.AsInteger());
diff --git a/src/darwin/Framework/CHIP/MTRDeviceConnectionBridge.h b/src/darwin/Framework/CHIP/MTRDeviceConnectionBridge.h
index 95148931005c42..a748d8b2dba34c 100644
--- a/src/darwin/Framework/CHIP/MTRDeviceConnectionBridge.h
+++ b/src/darwin/Framework/CHIP/MTRDeviceConnectionBridge.h
@@ -50,7 +50,7 @@ class MTRDeviceConnectionBridge : public chip::ReferenceCounted<MTRDeviceConnect
     chip::Callback::Callback<chip::OnDeviceConnectionFailure> mOnConnectFailed;
 
     static void OnConnected(void * context, chip::OperationalDeviceProxy * device);
-    static void OnConnectionFailure(void * context, chip::PeerId peerId, CHIP_ERROR error);
+    static void OnConnectionFailure(void * context, const chip::ScopedNodeId & peerId, CHIP_ERROR error);
 };
 
 NS_ASSUME_NONNULL_END
diff --git a/src/darwin/Framework/CHIP/MTRDeviceConnectionBridge.mm b/src/darwin/Framework/CHIP/MTRDeviceConnectionBridge.mm
index 2ad2c2f6c08f83..da739514e3b4c1 100644
--- a/src/darwin/Framework/CHIP/MTRDeviceConnectionBridge.mm
+++ b/src/darwin/Framework/CHIP/MTRDeviceConnectionBridge.mm
@@ -29,7 +29,7 @@
     });
 }
 
-void MTRDeviceConnectionBridge::OnConnectionFailure(void * context, chip::PeerId peerId, CHIP_ERROR error)
+void MTRDeviceConnectionBridge::OnConnectionFailure(void * context, const chip::ScopedNodeId & peerId, CHIP_ERROR error)
 {
     auto * object = static_cast<MTRDeviceConnectionBridge *>(context);
     dispatch_async(object->mQueue, ^{