Skip to content

Commit ce3df4d

Browse files
authored
Merge pull request #3 from smartcontractkit/fix/storageSlotId-slotId
2 parents bbc061a + 40d6a83 commit ce3df4d

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-18
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@chainlink/functions-toolkit': patch
3+
---
4+
5+
Renamed storageSlotId to slotId for SecretsManager.uploadEncryptedSecretsToDON()

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ const encryptedSecrets = await secretsManager.encryptSecrets({
340340

341341
Encrypted secrets can be uploaded directly to the DON via gateway URLs such that they can be used when making an on-chain request. This is accomplished by sending a signed POST request to gateway URLs which are connected to the DON. The DON then maintains a decentralized database with eventual consistency, such that the stored values will propagate to all DON nodes. To ensure redundancy, it is always recommended to send encrypted secrets storage requests to multiple gateway URLs.
342342

343-
First, encrypt the secrets with [`encryptSecrets()`](#encrypting-secrets). Then, pass the `encryptedSecrets` hex string in an object to the `uploadEncryptedSecretsToDON()` method as shown below. The `storageSlotId` can be any integer value of zero or greater, however using a previously used slot ID will overwrite the existing data. After `minutesUntilExpiration`, the entry will be deleted from all DON nodes. Get the list of valid gateway URLs for each blockchain network from the [Chainlink Functions documentation](https://docs.chain.link/chainlink-functions/supported-networks).
343+
First, encrypt the secrets with [`encryptSecrets()`](#encrypting-secrets). Then, pass the `encryptedSecrets` hex string in an object to the `uploadEncryptedSecretsToDON()` method as shown below. The `slotId` can be any integer value of zero or greater, however using a previously used slot ID will overwrite the existing data. After `minutesUntilExpiration`, the entry will be deleted from all DON nodes. Get the list of valid gateway URLs for each blockchain network from the [Chainlink Functions documentation](https://docs.chain.link/chainlink-functions/supported-networks).
344344

345345
```
346346
const encryptedSecretsObj = await secretsManager.encryptSecrets({ my: 'secret' })
@@ -353,7 +353,7 @@ const {
353353
} = await secretsManager.uploadEncryptedSecretsToDON({
354354
encryptedSecretsHexstring: encryptedSecretsObj.encryptedSecrets,
355355
gatewayUrls: [ 'https://exampleGatewayUrl1.com/gateway', 'https://exampleGatewayUrl2.com/gateway', ... ],
356-
storageSlotId: mySlotIdNumber,
356+
slotId: mySlotIdNumber,
357357
minutesUntilExpiration: myExpirationTimeInMinutes,
358358
})
359359
```

src/SecretsManager.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,12 @@ export class SecretsManager {
186186
public async uploadEncryptedSecretsToDON({
187187
encryptedSecretsHexstring,
188188
gatewayUrls,
189-
storageSlotId,
189+
slotId,
190190
minutesUntilExpiration,
191191
}: {
192192
encryptedSecretsHexstring: string
193193
gatewayUrls: string[]
194-
storageSlotId: number
194+
slotId: number
195195
minutesUntilExpiration: number
196196
}): Promise<{ version: number; success: boolean }> {
197197
this.isInitialized()
@@ -201,8 +201,8 @@ export class SecretsManager {
201201
throw Error('encryptedSecretsHexstring must be a valid hex string')
202202
}
203203

204-
if (!Number.isInteger(storageSlotId) || storageSlotId < 0) {
205-
throw Error('storageSlotId must be a integer of at least 0')
204+
if (!Number.isInteger(slotId) || slotId < 0) {
205+
throw Error('slotId must be a integer of at least 0')
206206
}
207207

208208
if (!Number.isInteger(minutesUntilExpiration) || minutesUntilExpiration < 5) {
@@ -219,7 +219,7 @@ export class SecretsManager {
219219

220220
const message = {
221221
address: signerAddressBase64,
222-
slotid: storageSlotId,
222+
slotid: slotId,
223223
payload: encryptedSecretsBase64,
224224
version: secretsVersion,
225225
expiration: secretsExpiration,
@@ -228,7 +228,7 @@ export class SecretsManager {
228228
const storageSignatureBase64 = Buffer.from(storageSignature.slice(2), 'hex').toString('base64')
229229

230230
const payload = {
231-
slot_id: storageSlotId,
231+
slot_id: slotId,
232232
version: secretsVersion,
233233
payload: encryptedSecretsBase64,
234234
expiration: secretsExpiration,

test/integration/integration.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,7 @@ describe('Functions toolkit classes', () => {
15671567
'https://dongateway.com/uploadSuccess1',
15681568
'https://dongateway.com/uploadSuccess2',
15691569
],
1570-
storageSlotId: 0,
1570+
slotId: 0,
15711571
minutesUntilExpiration: 10,
15721572
})
15731573

@@ -1584,7 +1584,7 @@ describe('Functions toolkit classes', () => {
15841584
const result = await sm.uploadEncryptedSecretsToDON({
15851585
encryptedSecretsHexstring: '0xaaaa',
15861586
gatewayUrls: ['https://dongateway.com/1NodeFail'],
1587-
storageSlotId: 0,
1587+
slotId: 0,
15881588
minutesUntilExpiration: 10,
15891589
})
15901590

@@ -1603,7 +1603,7 @@ describe('Functions toolkit classes', () => {
16031603
await sm.uploadEncryptedSecretsToDON({
16041604
encryptedSecretsHexstring: '0xaaaa',
16051605
gatewayUrls: ['https://dongateway.com/allNodeFail'],
1606-
storageSlotId: 0,
1606+
slotId: 0,
16071607
minutesUntilExpiration: 10,
16081608
}),
16091609
).rejects.toThrow(/All nodes failed to store the encrypted secrets/)
@@ -1618,7 +1618,7 @@ describe('Functions toolkit classes', () => {
16181618
await sm.uploadEncryptedSecretsToDON({
16191619
encryptedSecretsHexstring: '0xaaaa',
16201620
gatewayUrls: [],
1621-
storageSlotId: 0,
1621+
slotId: 0,
16221622
minutesUntilExpiration: 10,
16231623
}),
16241624
).rejects.toThrow(/gatewayUrls must be a non-empty array of strings/)
@@ -1633,7 +1633,7 @@ describe('Functions toolkit classes', () => {
16331633
await sm.uploadEncryptedSecretsToDON({
16341634
encryptedSecretsHexstring: '0xaaaa',
16351635
gatewayUrls: ['Invalid URL'],
1636-
storageSlotId: 0,
1636+
slotId: 0,
16371637
minutesUntilExpiration: 10,
16381638
}),
16391639
).rejects.toThrow(/is not a valid URL/)
@@ -1648,7 +1648,7 @@ describe('Functions toolkit classes', () => {
16481648
await sm.uploadEncryptedSecretsToDON({
16491649
encryptedSecretsHexstring: 'aaaa',
16501650
gatewayUrls: ['https://dongateway.com/uploadSuccess1'],
1651-
storageSlotId: 0,
1651+
slotId: 0,
16521652
minutesUntilExpiration: 10,
16531653
}),
16541654
).rejects.toThrow(/encryptedSecretsHexstring must be a valid hex string/)
@@ -1663,10 +1663,10 @@ describe('Functions toolkit classes', () => {
16631663
await sm.uploadEncryptedSecretsToDON({
16641664
encryptedSecretsHexstring: '0xaaaa',
16651665
gatewayUrls: ['https://dongateway.com/uploadSuccess1'],
1666-
storageSlotId: -1,
1666+
slotId: -1,
16671667
minutesUntilExpiration: 10,
16681668
}),
1669-
).rejects.toThrow(/storageSlotId must be a integer of at least 0/)
1669+
).rejects.toThrow(/slotId must be a integer of at least 0/)
16701670
})
16711671

16721672
it('Throws error for invalid expiration', async () => {
@@ -1678,7 +1678,7 @@ describe('Functions toolkit classes', () => {
16781678
await sm.uploadEncryptedSecretsToDON({
16791679
encryptedSecretsHexstring: '0xaaaa',
16801680
gatewayUrls: ['https://dongateway.com/uploadSuccess1'],
1681-
storageSlotId: 0,
1681+
slotId: 0,
16821682
minutesUntilExpiration: 4,
16831683
}),
16841684
).rejects.toThrow(/minutesUntilExpiration must be an integer of at least 5/)
@@ -1695,7 +1695,7 @@ describe('Functions toolkit classes', () => {
16951695
await sm.uploadEncryptedSecretsToDON({
16961696
encryptedSecretsHexstring: '0xaaaa',
16971697
gatewayUrls: ['https://dongateway.com/uploadSuccess1', 'https://dongateway.com/fail'],
1698-
storageSlotId: 0,
1698+
slotId: 0,
16991699
minutesUntilExpiration: 10,
17001700
}),
17011701
).rejects.toThrow(

0 commit comments

Comments
 (0)