From 11e237867df80bc21e1c89abcfc469707dea5310 Mon Sep 17 00:00:00 2001 From: Derek Sonnenberg Date: Thu, 16 Jan 2025 23:30:53 -0600 Subject: [PATCH 1/2] fix(arconnect): use signDataItem method, signature is deprecated --- src/utils/ao.ts | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/utils/ao.ts b/src/utils/ao.ts index 0895486e..1311cb69 100644 --- a/src/utils/ao.ts +++ b/src/utils/ao.ts @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { createData } from '@dha-team/arbundles'; +import { ArconnectSigner, DataItem, createData } from '@dha-team/arbundles'; import { connect, createDataItemSigner } from '@permaweb/aoconnect'; import Arweave from 'arweave'; import { z } from 'zod'; @@ -237,6 +237,28 @@ export function createAoSigner(signer: ContractSigner): AoSigner { ) { await signer.setPublicKey(); } + if (signer instanceof ArconnectSigner) { + try { + // Sign using Arconnect signDataItem API + const signedDataItem = await signer['signer'].signDataItem({ + data, + tags, + target, + anchor, + }); + const dataItem = new DataItem(Buffer.from(signedDataItem)); + return { + id: await dataItem.id, + raw: await dataItem.getRaw(), + }; + } catch (e) { + console.error( + 'Failed to sign data item, falling back to default signer method', + e, + ); + } + } + const dataItem = createData(data, signer, { tags, target, anchor }); const signedData = dataItem.sign(signer).then(async () => ({ id: await dataItem.id, From 6a80633c06b16a310c513875f3e96556f1fae236 Mon Sep 17 00:00:00 2001 From: Derek Sonnenberg Date: Fri, 17 Jan 2025 09:24:14 -0600 Subject: [PATCH 2/2] refactor(arconnect): remove fallback, only use signDataItem api --- src/utils/ao.ts | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/src/utils/ao.ts b/src/utils/ao.ts index 1311cb69..f61d4a79 100644 --- a/src/utils/ao.ts +++ b/src/utils/ao.ts @@ -238,25 +238,18 @@ export function createAoSigner(signer: ContractSigner): AoSigner { await signer.setPublicKey(); } if (signer instanceof ArconnectSigner) { - try { - // Sign using Arconnect signDataItem API - const signedDataItem = await signer['signer'].signDataItem({ - data, - tags, - target, - anchor, - }); - const dataItem = new DataItem(Buffer.from(signedDataItem)); - return { - id: await dataItem.id, - raw: await dataItem.getRaw(), - }; - } catch (e) { - console.error( - 'Failed to sign data item, falling back to default signer method', - e, - ); - } + // Sign using Arconnect signDataItem API + const signedDataItem = await signer['signer'].signDataItem({ + data, + tags, + target, + anchor, + }); + const dataItem = new DataItem(Buffer.from(signedDataItem)); + return { + id: await dataItem.id, + raw: await dataItem.getRaw(), + }; } const dataItem = createData(data, signer, { tags, target, anchor });