When you say lost power am guessing you lost your electrical power while you were driving, this is common when the ignition switch has gone bad and will need to be replaced. Extra weight on the ignition switch from extra keys will do this, the other thing to would be a bad wire harness from the ignition switch to the the fuse block.
This is such a common problem. If weird things start happening with your truck and nothing seems to make any sense the culprit could possibly be the ignition switch.
The ignition switch uses a gear that has a few different ramps on either side of it. When you turn the key, the ignition cylinder drives the gear into its different positions. As the ramps pass under each of the small little followers, it acts as a sort of cam that pushes on each of the contact arms. The pictures below do not include any of the gear detents and the main spring on the gear has also been removed (the spring is what pushes the key back after you have started the vehicle).
As you can see, there are five main contacts in the switch. These contacts control everything in the truck. For instance, the large brown wire in the middle/top portion of the switch is the accessory power wire which feeds into the RAP (retained accessory power) relay then off to all the accessory items (radio, windows, etc). The large orange wire is the IGN 3 wire which powers the ABS, HVAC, 4WD, and cruise systems. The large pink wire is the IGN 1 wire that powers the ECM, ENG 1 fuse, O2 sensors, B/U lamps, DRLs, A/C relay, etc.
On the other side, you have the small white wire which feeds the IGN 0 circuit (cluster) and the small yellow wire which feeds into the starter circuit. These two items get power from the small red wire (IGN C fuse) when their respective contacts connect.
Here is a run down of what circuits have power for a given key position (ACC, LOCK, OFF, RUN, & START):
* IGN 0 (small white wire) circuit has power in OFF, RUN, and START
* CRANK (small yellow wire) circuit only has power in START
* ACC/RAP (large brown wire) circuit has power in ACC and RUN
* IGN 1 (large pink wire) circuit has power in RUN and START
* IGN 3 (large orange wire) circuit has power in RUN only
Since some of the circuits can have a fairly high current load on them when you start your truck, the arc that happens when the contacts close can be pretty intense. Over time, the contacts will erode/corrode and will loose their conductivity to each other, usually in the form of a higher resistance. This higher resistance also causes heat which further exacerbates the problem.
The IGN 3 contacts are the most heavily loaded of all of the contacts in the system and it also is the contact which is opened and closed the most during the life of the truck. Lets look closer at what this contact goes through on a normal start sequence. In a typical start cycle, the key is turned from LOCK, through OFF and RUN, then to START, and finally back to RUN once the vehicle is started. As the key is turned from LOCK to RUN, the IGN 3 contacts close. When the key is then turned to START, the contacts open back up. Once returned to RUN, the contacts close again. This is why it is vitally important to hold the key in the START position until you are sure that the engine is running. The more times you go to the START position, the more life you take away from these contacts.
For the 98+ trucks, the most common issue is the "security" light on the dash illuminating. But the problem can also manifest itself as an inoperative fuel pump, unresponsive cluster, ABS and/or SIR lights being illuminated on the cluster, as well as a no start condition (either related to the inoperative fuel pump or a failure of the starter to turn over). The ignition switch can also cause PASSLOCK issues.
Hope this helps you trace the issues your Sonoma has.