@fogo/sessions-sdk 0.1.5 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/connection.js +10 -3
- package/cjs/index.js +28 -2
- package/esm/connection.js +10 -3
- package/esm/index.js +28 -2
- package/package.json +1 -1
package/cjs/connection.js
CHANGED
|
@@ -157,9 +157,16 @@ const buildTollboothInstructionIfNeeded = ({ sessionKeyAddress, walletPublicKey,
|
|
|
157
157
|
return undefined;
|
|
158
158
|
}
|
|
159
159
|
};
|
|
160
|
-
const addSignaturesToExistingTransaction = (transaction, signerKeys) =>
|
|
161
|
-
|
|
162
|
-
|
|
160
|
+
const addSignaturesToExistingTransaction = async (transaction, signerKeys) => {
|
|
161
|
+
const kitTransaction = transaction instanceof web3_js_1.VersionedTransaction
|
|
162
|
+
? (0, compat_1.fromVersionedTransaction)(transaction) // VersionedTransaction has a lifetime so it's fine to cast it so we can call partiallySignTransaction
|
|
163
|
+
: transaction;
|
|
164
|
+
const signerAddresses = await Promise.all(signerKeys.map(async (signer) => [signer, await (0, kit_1.getAddressFromPublicKey)(signer.publicKey)]));
|
|
165
|
+
const filteredSignerKeys = signerAddresses
|
|
166
|
+
.filter(([, address]) => kitTransaction.signatures[address] !== undefined)
|
|
167
|
+
.map(([signer]) => signer);
|
|
168
|
+
return (0, kit_1.partiallySignTransaction)(filteredSignerKeys, kitTransaction);
|
|
169
|
+
};
|
|
163
170
|
const getSignerKeys = async (sessionKey, extraSigners) => {
|
|
164
171
|
const extraSignerKeys = extraSigners === undefined
|
|
165
172
|
? []
|
package/cjs/index.js
CHANGED
|
@@ -131,10 +131,36 @@ const getSessionAccount = async (connection, sessionPublicKey) => {
|
|
|
131
131
|
: sessionInfoSchema.parse(new anchor_1.BorshAccountsCoder(sessions_idls_1.SessionManagerIdl).decode("Session", result.data));
|
|
132
132
|
};
|
|
133
133
|
exports.getSessionAccount = getSessionAccount;
|
|
134
|
+
const getDomainRegistryAuthorizedPrograms = async (connection, domain) => {
|
|
135
|
+
const result = await connection.getAccountInfo((0, exports.getDomainRecordAddress)(domain), "confirmed");
|
|
136
|
+
if (result === null) {
|
|
137
|
+
return [];
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
const programs = [];
|
|
141
|
+
for (let i = 0; i < result.data.length; i += 64) {
|
|
142
|
+
programs.push({
|
|
143
|
+
programId: new web3_js_1.PublicKey(result.data.subarray(i, i + 32)),
|
|
144
|
+
signerPda: new web3_js_1.PublicKey(result.data.subarray(i + 32, i + 64)),
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
return programs;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
const authorizedProgramsMatchDomainRegistry = (sessionAuthorizedPrograms, domainAuthorizedPrograms) => {
|
|
151
|
+
if (sessionAuthorizedPrograms.type === AuthorizedProgramsType.All) {
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
return domainAuthorizedPrograms.every(({ programId: programIdFromRegistry }) => sessionAuthorizedPrograms.programs.some(({ programId }) => programId.equals(programIdFromRegistry)));
|
|
155
|
+
};
|
|
134
156
|
const createSession = async (context, walletPublicKey, sessionKey) => {
|
|
135
157
|
const sessionPublicKey = new web3_js_1.PublicKey(await (0, kit_1.getAddressFromPublicKey)(sessionKey.publicKey));
|
|
136
|
-
const sessionInfo = await
|
|
137
|
-
|
|
158
|
+
const [sessionInfo, domainRegistryAuthorizedPrograms] = await Promise.all([
|
|
159
|
+
(0, exports.getSessionAccount)(context.connection, sessionPublicKey),
|
|
160
|
+
getDomainRegistryAuthorizedPrograms(context.connection, context.domain),
|
|
161
|
+
]);
|
|
162
|
+
return sessionInfo === undefined ||
|
|
163
|
+
!authorizedProgramsMatchDomainRegistry(sessionInfo.authorizedPrograms, domainRegistryAuthorizedPrograms)
|
|
138
164
|
? undefined
|
|
139
165
|
: {
|
|
140
166
|
sessionPublicKey,
|
package/esm/connection.js
CHANGED
|
@@ -150,9 +150,16 @@ const buildTollboothInstructionIfNeeded = ({ sessionKeyAddress, walletPublicKey,
|
|
|
150
150
|
return undefined;
|
|
151
151
|
}
|
|
152
152
|
};
|
|
153
|
-
const addSignaturesToExistingTransaction = (transaction, signerKeys) =>
|
|
154
|
-
|
|
155
|
-
|
|
153
|
+
const addSignaturesToExistingTransaction = async (transaction, signerKeys) => {
|
|
154
|
+
const kitTransaction = transaction instanceof VersionedTransaction
|
|
155
|
+
? fromVersionedTransaction(transaction) // VersionedTransaction has a lifetime so it's fine to cast it so we can call partiallySignTransaction
|
|
156
|
+
: transaction;
|
|
157
|
+
const signerAddresses = await Promise.all(signerKeys.map(async (signer) => [signer, await getAddressFromPublicKey(signer.publicKey)]));
|
|
158
|
+
const filteredSignerKeys = signerAddresses
|
|
159
|
+
.filter(([, address]) => kitTransaction.signatures[address] !== undefined)
|
|
160
|
+
.map(([signer]) => signer);
|
|
161
|
+
return partiallySignTransaction(filteredSignerKeys, kitTransaction);
|
|
162
|
+
};
|
|
156
163
|
const getSignerKeys = async (sessionKey, extraSigners) => {
|
|
157
164
|
const extraSignerKeys = extraSigners === undefined
|
|
158
165
|
? []
|
package/esm/index.js
CHANGED
|
@@ -111,10 +111,36 @@ export const getSessionAccount = async (connection, sessionPublicKey) => {
|
|
|
111
111
|
? undefined
|
|
112
112
|
: sessionInfoSchema.parse(new BorshAccountsCoder(SessionManagerIdl).decode("Session", result.data));
|
|
113
113
|
};
|
|
114
|
+
const getDomainRegistryAuthorizedPrograms = async (connection, domain) => {
|
|
115
|
+
const result = await connection.getAccountInfo(getDomainRecordAddress(domain), "confirmed");
|
|
116
|
+
if (result === null) {
|
|
117
|
+
return [];
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
const programs = [];
|
|
121
|
+
for (let i = 0; i < result.data.length; i += 64) {
|
|
122
|
+
programs.push({
|
|
123
|
+
programId: new PublicKey(result.data.subarray(i, i + 32)),
|
|
124
|
+
signerPda: new PublicKey(result.data.subarray(i + 32, i + 64)),
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
return programs;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
const authorizedProgramsMatchDomainRegistry = (sessionAuthorizedPrograms, domainAuthorizedPrograms) => {
|
|
131
|
+
if (sessionAuthorizedPrograms.type === AuthorizedProgramsType.All) {
|
|
132
|
+
return true;
|
|
133
|
+
}
|
|
134
|
+
return domainAuthorizedPrograms.every(({ programId: programIdFromRegistry }) => sessionAuthorizedPrograms.programs.some(({ programId }) => programId.equals(programIdFromRegistry)));
|
|
135
|
+
};
|
|
114
136
|
const createSession = async (context, walletPublicKey, sessionKey) => {
|
|
115
137
|
const sessionPublicKey = new PublicKey(await getAddressFromPublicKey(sessionKey.publicKey));
|
|
116
|
-
const sessionInfo = await
|
|
117
|
-
|
|
138
|
+
const [sessionInfo, domainRegistryAuthorizedPrograms] = await Promise.all([
|
|
139
|
+
getSessionAccount(context.connection, sessionPublicKey),
|
|
140
|
+
getDomainRegistryAuthorizedPrograms(context.connection, context.domain),
|
|
141
|
+
]);
|
|
142
|
+
return sessionInfo === undefined ||
|
|
143
|
+
!authorizedProgramsMatchDomainRegistry(sessionInfo.authorizedPrograms, domainRegistryAuthorizedPrograms)
|
|
118
144
|
? undefined
|
|
119
145
|
: {
|
|
120
146
|
sessionPublicKey,
|