1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
* Copyright (c) 2025- Mark Hughes
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use ;
use SecretKey;
/// Each mutable type has an address derived from three pieces of information:
/// - an owner secret
/// - a derivation index (which prevents clashes between types)
/// - a name (which allows the same owner to create more than one instance of each type)
///
/// The owner secret is supplied to the API and used with the derivation index
/// to derive an owner secret per type (see derive_owner_secret_for_type())
/// The owner secret and name are provided to the API by an app, whereas
/// the following derivation indices are fixed by dweb. Other libraries
/// can use the same approach with the same derivation indices in order
/// to allow different apps to access the same objects providing they
/// have the owner secret and know the name used to create the object.
///
/// Derivation indices for each mutable Autonomi type:
/// Note: the string must be exactly 32 bytes long and different from all other indices
pub const POINTER_DERIVATION_INDEX: &str = "Pointer derivatation index ";
pub const GRAPHENTRY_DERIVATION_INDEX: &str = "GraphEntry derivatation index ";
pub const PRIVATE_SCRATCHPAD_DERIVATION_INDEX: &str = "PublicScratchpad derivn. index ";
pub const PUBLIC_SCRATCHPAD_DERIVATION_INDEX: &str = "PrivateScratchpad derivn. index ";
// TODO see autonomi::access::keys and notes in Zim
// pub const VAULT_DERIVATION_INDEX: &str = "Vault derivatation index ";
// pub const REGISTER_DERIVATION_INDEX: &str = "Register derivatation index ";
///
/// Derivation indices for each mutable Dweb type:
/// Note: A dweb History doesn't have its own derivation index. Instead because it
/// is a generic type and uses the trove_type() to ensure each specific History
/// type has a separate derivation index.
pub const HISTORY_POINTER_DERIVATION_INDEX: &str = "History Pointer derivatatn. indx";
// /// Get the main secret key for all Pointers belonging to an owner
// pub fn pointer_secret_key_from_owner(owner_secret: SecretKey) -> SecretKey {
// derive_type_owner_secret(owner_secret, POINTER_DERIVATION_INDEX)
// }
// /// Get the main secret key for all GraphEntry objects belonging to an owner
// pub fn graphentry_secret_key_from_owner(owner_secret: SecretKey) -> SecretKey {
// derive_type_owner_secret(owner_secret, GRAPHENTRY_DERIVATION_INDEX)
// }
// /// Get the main secret key for all Scratchpads belonging to an owner
// pub fn scratchpad_secret_key_from_owner(owner_secret: SecretKey) -> SecretKey {
// derive_type_owner_secret(owner_secret, SCRATCHPAD_DERIVATION_INDEX)
// }
// // /// Get the main secret key for all Vaults belonging to an owner
// // /// TODO see autonomi::access::keys and notes in Zim
// // pub fn vault_secret_key_from_owner(owner_secret: SecretKey) -> SecretKey {
// // derive_type_owner_secret(owner_secret, VAULT_DERIVATION_INDEX)
// // }
// /// Get the main secret key for all Register belonging to an owner
// /// TODO see autonomi::access::keys and notes in Zim
// pub fn register_secret_key_from_owner(owner_secret: SecretKey) -> SecretKey {
// derive_type_owner_secret(owner_secret, REGISTER_DERIVATION_INDEX)
// }
/// Derive the object owner secret when creating a mutable data object (e.g. Pointer or Scratchpad)
///
/// The owner_secret for a mutable objecct is based on the dweb derivation key for the type or a supplied string, an
/// optional object name and optional app identifying strings from request headers.
///
/// If all mutable objects were created with the owner_secret they would all have the same address and only one
/// would be permitted. To allow multiple objects to be created, the secret used to create them can be derived
/// from from the owner secret using one or more derivation indexes (32 byte sequences) or strings (such as an app identifier
/// and object name).
/// Derive the object owner secret based on the dweb derivation key for the type or a supplied str, and an
/// optional object name