feat(ios): hashcash in swift (#8602)

This commit is contained in:
Brooooooklyn
2024-10-29 08:40:15 +00:00
parent efee4dfd66
commit 5709ebbb11
10 changed files with 152 additions and 9 deletions
+12 -1
View File
@@ -4,7 +4,11 @@ import { Telemetry } from '@affine/core/components/telemetry';
import { configureMobileModules } from '@affine/core/mobile/modules';
import { router } from '@affine/core/mobile/router';
import { configureCommonModules } from '@affine/core/modules';
import { AuthService, WebSocketAuthProvider } from '@affine/core/modules/cloud';
import {
AuthService,
ValidatorProvider,
WebSocketAuthProvider,
} from '@affine/core/modules/cloud';
import { I18nProvider } from '@affine/core/modules/i18n';
import { configureLocalStorageStateStorageImpls } from '@affine/core/modules/storage';
import { PopupWindowProvider } from '@affine/core/modules/url';
@@ -28,6 +32,7 @@ import { RouterProvider } from 'react-router-dom';
import { configureFetchProvider } from './fetch';
import { Cookie } from './plugins/cookie';
import { Hashcash } from './plugins/hashcash';
const future = {
v7_startTransition: true,
@@ -66,6 +71,12 @@ framework.impl(WebSocketAuthProvider, {
};
},
});
framework.impl(ValidatorProvider, {
async validate(_challenge, resource) {
const res = await Hashcash.hash({ challenge: resource });
return res.value;
},
});
const frameworkProvider = framework.provider();
// setup application lifecycle events, and emit application start event
@@ -0,0 +1,6 @@
export interface HashcashPlugin {
hash(options: {
challenge: string;
bits?: number;
}): Promise<{ value: string }>;
}
@@ -0,0 +1,8 @@
import { registerPlugin } from '@capacitor/core';
import type { HashcashPlugin } from './definitions';
const Hashcash = registerPlugin<HashcashPlugin>('Hashcash');
export * from './definitions';
export { Hashcash };